忧里修斯 发表于 2013-1-15 02:36:20

windows下Python调用dll

一、使用VC++生成一个.dll文件
1、打开VC++新建一个“Win32 Dynamic_Link Library”空工程
2、编写头文件Lib.h
#ifndef LIB_H#define LIB_Hextern "C" int __declspec(dllexport)add(int x, int y);#endif
3、编写主文件util.cpp
#include "Lib.h"int add(int x, int y){    return x + y;}
4、将util.cpp“组建”pdll.dll文件

二、在Python中使用
test.py
# -*- coding:UTF-8 -*-from ctypes import *import os#加载刚才生成的.dll文件cUtil = cdll.LoadLibrary(r'E:\work\pstudy\src\pythonC\pdll.dll')print cUtil.add(1,2)
页: [1]
查看完整版本: windows下Python调用dll