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

yipeiwu_com5年前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实现决策树、随机森林的简单原理

python实现决策树、随机森林的简单原理

本文申明:此文为学习记录过程,中间多处引用大师讲义和内容。 一、概念 决策树(Decision Tree)是一种简单但是广泛使用的分类器。通过训练数据构建决策树,可以高效的对未知的数据进...

python飞机大战pygame碰撞检测实现方法分析

本文实例讲述了python飞机大战pygame碰撞检测实现方法。分享给大家供大家参考,具体如下: 目标 了解碰撞检测方法 碰撞实现 01. 了解碰撞检测方法 pygam...

Python 使用threading+Queue实现线程池示例

一、线程池 1、为什么需要使用线程池 1.1 创建/销毁线程伴随着系统开销,过于频繁的创建/销毁线程,会很大程度上影响处理效率。 记创建线程消耗时间T1,执行任务消耗时间T2,销毁线程...

python实现ping的方法

本文实例讲述了python实现ping的方法。分享给大家供大家参考。具体如下: #!/usr/bin/env python #coding:utf-8 import os, sys,...

python 多个参数不为空校验方法

在实际开发中经常需要对前端传递的多个参数进行不为空校验,可以使用python提供的all()函数 if not all([arg1, arg2, arg3]): # 当 arg1,...