欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-08-14 09:05:46
第一步,建立一个cpp的dll工程,然后写如下代码,生成dll 复制代码 代码如下:#include    &...

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