在python 中调用Dll

来源:互联网 发布:apache重启不了 编辑:程序博客网 时间:2024/05/16 18:59

1.首先写DLL文件,环境是在VC 6.0中

如下所示:

// funDll.cpp : Defines the entry point for the DLL application.//#include "stdafx.h"#include <iostream>using namespace std;#ifdef _MANAGED#pragma managed(push, off)#endif#ifdef __cplusplus #define EXPORT extern "C"__declspec(dllexport)#else#define EXPORT __declspec(dllexport)#endifEXPORT int HelloWorld(){ cout <<"hello world" <<endl; return 0;}BOOL APIENTRY DllMain( HMODULE hModule,                       DWORD  ul_reason_for_call,                       LPVOID lpReserved      ){    return TRUE;}#ifdef _MANAGED#pragma managed(pop)#endif

2.然后书写python调用DLL代码。

#coding=utf-8'''Created on 2011-12-5@author: LONMID'''from ctypes import *fileName = "funDll.dll"func = cdll.LoadLibrary(fileName)#print func.HelloWorld()ffd天下第一func.HelloWorld()

如果出现"Hello world",说明运行成功。

原创粉丝点击