c++生成dll使用python调用dll的方法
时间:2021-04-01 08:18:42|栏目:Python代码|点击: 次
第一步,建立一个CPP的DLL工程,然后写如下代码,生成DLL
复制代码 代码如下:
#include <stdio.h>
#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()
栏 目:Python代码
下一篇:Python for Informatics 第11章之正则表达式(二)
本文地址:http://www.codeinn.net/misctech/92406.html






