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)
#endif
EXPORT 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",说明运行成功。