1、新建win32控制台应用程序,名字为dllname,应用程序类型选dll,完成.
2、dllname.cpp中增加代码:
#include "stdafx.h"
extern "C" __declspec(dllexport) int __stdcall Sum(int a, int b)
{
return a+b;
}
3、生成,dll创建出来
4、建立test.py文件:
import ctypes
a = ctypes.windll.LoadLibrary('dllname.dll')
test = a.Sum
test.argtypes = [ctypes.c_int, ctypes.c_int]
test.restypes = ctypes.c_int
print test(1,2)
运行成功输出 结果3