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画小女孩放风筝的示例

用Python画小女孩放风筝的示例

我就废话不多说了,直接上代码吧! # coding:utf-8 2import turtle as t 3import random 4# 画心 5def xin(): 6...

python接口自动化如何封装获取常量的类

这篇文章主要介绍了python接口自动化如何封装获取常量的类,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 背景: 一、执行case的...

win7安装python生成随机数代码分享

复制代码 代码如下:import random def genrand(small, big) :    return small + (big-small...

跟老齐学Python之大话题小函数(2)

跟老齐学Python之大话题小函数(2)

上一讲和本讲的标题是“大话题小函数”,所谓大话题,就是这些函数如果溯源,都会找到听起来更高大上的东西。这种思维方式绝对我坚定地继承了中华民族的优良传统的。自从天朝的臣民看到英国人开始踢足...

Python检测网络延迟的代码

本文讲述了Python检测网络延迟的代码。分享给大家供大家参考,具体如下: #!/usr/bin/env python # coding: utf-8 # coding: cp9...