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发送带header的http请求方法详解

简单的header import urllib2 request = urllib2.Request('http://example.com/') request.add_he...

python 模拟创建seafile 目录操作示例

本文实例讲述了python 模拟创建seafile 目录操作。分享给大家供大家参考,具体如下: # !/usr/bin/env python # -*- coding: utf-8...

python实现小球弹跳效果

python实现小球弹跳效果

本文实例为大家分享了python实现小球弹跳效果的具体代码,供大家参考,具体内容如下 import pygame, sys pygame.init() screenGameC...

python中ConfigParse模块的用法

本文实例讲述了python中ConfigParse模块的用法,分享给大家供大家参考。具体方法如下: 写配置一般用ConfigParse.RawConfigParse类 读配置用Conf...

Python内存管理方式和垃圾回收算法解析

概要 在列表,元组,实例,类,字典和函数中存在循环引用问题。有 __del__ 方法的实例会以健全的方式被处理。给新类型添加GC支持是很容易的。支持GC的Python与常规的Python...