>  기사  >  백엔드 개발  >  c++生成dll使用python调用dll的方法

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

WBOY
WBOY원래의
2016-06-16 08:45:381616검색

第一步,建立一个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()
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.