中国开发网: 论坛: 超级垃圾站: 贴子 574350
龙之吻: python调用c的dll
test.c
#include <stdio.h>
#include <windows.h>
//---------------------------------------
//使用DLL
//---------------------------------------

__declspec(dllexport) int addnum1(int a)
{
return (a+1);
}

__declspec(dllexport) int addnum10(int a,char *ca)
{
sprintf(ca,"%d",a+10);
return (a+10);
}

//end of file
编译:
gcc -c test.c

gcc -shared -o test.dll test.o -Wl,--out-implib,libtest.a


#test.py文件

from ctypes import *

fileName="test.dll"
func=cdll.LoadLibrary(fileName)
a =c_int(2)
ret=c_int()
ret=func.addnum1(a)

print "value of a :",ret

b=c_int(20)
str=c_char_p("")
ret=func.addnum10(b,str)

print "return value is :",ret
print "the string is :",str.value


机器人,这首歌学会了没有?

我们的目标是->没有蛀牙!

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录