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校准本地时间的方法教程

1. 概念 1.1 基本概念 时间,对于我们来说很重要,什么时候做什么?什么时候发生什么?没有时间的概念,生活就乱了。 在日常的运维当中,我们更关注告警的时间:什么时候发生、什么事故...

python实现截取屏幕保存文件,删除N天前截图的例子

我就废话不多说,直接上代码吧! from PIL import ImageGrab import time import schedule import os import shut...

Python使用matplotlib实现在坐标系中画一个矩形的方法

Python使用matplotlib实现在坐标系中画一个矩形的方法

本文实例讲述了Python使用matplotlib实现在坐标系中画一个矩形的方法。分享给大家供大家参考。具体实现方法如下: import matplotlib.pyplot as p...

python语言基本语句用法总结

python语句与语法 1.python简单语句的基本介绍 >>> while True: #简单的while循环 ... reply = input('Ente...

Python上下文管理器类和上下文管理器装饰器contextmanager用法实例分析

本文实例讲述了Python上下文管理器类和上下文管理器装饰器contextmanager用法。分享给大家供大家参考,具体如下: 一. 什么是上下文管理器 上下文管理器是在Python2....