码迷,mamicode.com
首页 > 编程语言 > 详细

[C++/Python] 如何在Python中使用一个DLL? (Windows环境)

时间:2014-10-20 15:04:49      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   sp   文件   div   on   log   

开发环境VS2012, WIN7 64.

首先生成的DLL大致如下:

.h文件

#ifdef CVINPYTHON_EXPORTS
#define CVINPYTHON_API __declspec(dllexport)
#else
#define CVINPYTHON_API __declspec(dllimport)
#endif

extern "C" 
{
    CVINPYTHON_API int addinPython(int, int);
};

.c文件

#include "stdafx.h"
#include "cvInPython.h"
extern "C" 
{
    CVINPYTHON_API int addinPython(int a, int b) {
        return a+b;
    }
};

之后在python中使用

import ctypes
dll = ctypes.CDLL( "dllname.dll" )

即可.

[C++/Python] 如何在Python中使用一个DLL? (Windows环境)

标签:style   blog   color   使用   sp   文件   div   on   log   

原文地址:http://www.cnblogs.com/lancelod/p/4037100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!