第一步,建立一个cpp的dll工程,然后写如下代码,生成dll
复制代码 代码如下:
#include
#define dllexport extern c __declspec(dllexport)
dllexport int __stdcall hello()
{
printf(hello world!\n);
return 0;
}
第二步,编写一个 python 文件:
复制代码 代码如下:
# coding: utf-8
import os
import ctypes
cur_path = os.path.dirname(__file__)
if __name__ == '__main__':
print 'starting...'
dll = ctypes.windll(os.path.join(cur_path, 'hello.dll'))
dll.hello()