当前位置: 移动技术网 > IT编程>脚本编程>Python > c++生成dll使用python调用dll的方法

c++生成dll使用python调用dll的方法

2019年04月02日  | 移动技术网IT编程  | 我要评论

冀中能源峰峰集团有限公司,民国之锦绣梅缘,郑焦公交

第一步,建立一个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()

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网