您的位置:首页 > 编程语言 > C语言/C++

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

2014-01-20 00:00 1096 查看
第一步,建立一个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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐