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 数据库的Connection、Cursor两大对象

详解Python 数据库的Connection、Cursor两大对象

Python 数据库图解流程 Connection、Cursor比喻 Connection()的参数列表 host,连接的数据库服务器主机名,默认为本地主机(localhost)。u...

Python中的左斜杠、右斜杠(正斜杠和反斜杠)

首先,"/"左倾斜是正斜杠,"\"右倾斜是反斜杠,可以记为:除号是正斜杠一般来说对于目录分隔符,Unix和Web用正斜杠/,Windows用反斜杠,但是现在Windows (一)目录中...

python基础教程之数字处理(math)模块详解

1.math简介复制代码 代码如下:>>> import math>>>dir(math)     ...

python同步两个文件夹下的内容

本文实例为大家分享了python同步两个文件夹下的内容,供大家参考,具体内容如下 import os import shutil import time import logging...

Python连接字符串过程详解

这篇文章主要介绍了python连接字符串过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 在python中,如果有多个字符串,想...