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

WBOY
Release: 2016-06-16 08:45:38
Original
1621 people have browsed it

第一步,建立一个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()
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!