[阅读: 1549] 2007-10-22 10:03:05
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
机器人,
这首歌学会了没有?
我们的目标是->没有蛀牙!