微录客福利,nospot,愿者上钩姬泱
1. 首先vc++的dll的导出函数定义成标准c的导出函数:
#ifdef lrdlltest_exports
#define lrdlltest_api __declspec(dllexport)
#else
#define lrdlltest_api __declspec(dllimport)
#endif
extern "c" lrdlltest_api int sum(int a , int b);
extern "c" lrdlltest_api void getstring(char* pchar);
//a + b
lrdlltest_api int sum(int a , int b)
{
return a + b;
}
//get a string
lrdlltest_api void getstring(char* pchar)
{
strcpy(pchar, "hello dll");
}
2. python中调用如下:
from ctypes import *
filename="lrdlltest.dll"
func=cdll.loadlibrary(filename)
str = create_string_buffer(20)
n = func.sum(2, 3)
func.getstring(str)
print n
print str.raw
关于c语言中的一些参数类型详见:http://www.python.org/doc/2.5/lib/node454.html
3. 输出结果:
5
hello dll
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
python如何查看网页代码
用python查看网页代码的方法:1、使用“import”导入requests包import requests2、使用requests包的get()函数通过网页...
[阅读全文]
-
-
python如何保存文本文件
python保存文本文件的方法:使用python内置的open()类可以打开文本文件,向文件里面写入数据可以用write()函数,写完之后,使用close()函...
[阅读全文]
-
python如何编写win程序
python可以编写win程序。win程序的格式是exe,下面我们就来看一下使用python编写exe程序的方法。编写好python程序后py2exe模块即可将...
[阅读全文]
-
-
-
-
-
-
网友评论