使用c/c++在windows上扩展python如何在python 中使用 windows dll 首先下载 ctypes 模块 说明在 http://starship.python.net/crew/theller/ctypes/reference.html 下面是我写的一个例子 首先写一个dll,源码如下#include < stdio.h> #include < windows.h> //--------------------------------------- //演示使用DLL //--------------------------------------- int APIENTRY __declspec(dllexport) addnum1(int a){ return (a+1); } int APIENTRY __declspec(dllexport) addnum10(int a,char *ca){ sprintf(ca,"%d",a+10); return (a+10); }使用bcc 5.5 如下编译bcc -tWD dll.c在 python 中调用 如下:from ctypes import * fileName="dll.dll" func=windll.LoadLibrary(fileName) a =c_int(2) #convert to c type ret=c_int() ret=func.addnum1(a) print "value of a :",ret b=c_int(20) str=c_char_p("") #char point ret=func.addnum10(b,str) print "return value is :",ret print "the string is :",str.value #windll.FreeLibrary(func)输出结果为value of a : 3 return value is : 30 the string is : 30
在python 中使用 windows dll
最新推荐文章于 2024-10-31 19:13:11 发布
