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

yipeiwu_com6年前Python基础

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

相关文章

Python中请不要再用re.compile了

Python中请不要再用re.compile了

前言 如果大家在网上搜索Python 正则表达式,你将会看到大量的垃圾文章会这样写代码: import re pattern = re.compile('正则表达式') text...

python批量复制图片到另一个文件夹

本文实例为大家分享了python批量复制图片到文件夹的具体代码,供大家参考,具体内容如下 直接上代码: # -*- coding: utf-8 -*- """ Created on...

python实现高斯判别分析算法的例子

python实现高斯判别分析算法的例子

高斯判别分析算法(Gaussian discriminat analysis) 高斯判别算法是一个典型的生成学习算法(关于生成学习算法可以参考我的另外一篇博客)。在这个算法中,我们假设p...

python 实现读取一个excel多个sheet表并合并的方法

如下所示: import xlrd import pandas as pd from pandas import DataFrame DATA_DIR = 'E:/'...

Python3 翻转二叉树的实现

Python3 翻转二叉树的实现

提出问题:翻转一棵二叉树。(除根结点以外) 原始二叉树: 新二叉树: 解题思路:遇见二叉树先想到递归。从最下层的叶子结点开始置换左右子节点,一直置换到到最上层的根结点的左右节点为止...