c++生成dll使用python调用dll的方法
c++生成dll使用python调用dll的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:第一步,建立一个CPP的DLL工程,然后写如下代码,生成DLL复制代码代码如下:#include#defineDLLEXPORTextern...

第一步,建立一个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学习
脚本专栏子分类