首先,用C++生成一个DLL,源码
dllmain.c
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
DLLIMPORT void HelloWorld()
MessageBox(0,"Hello World from DLL!\n","Hi",MB_ICONINFORMATION);
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
switch(fdwReason)
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
/* Return TRUE on success, FALSE on failure */
return TRUE;
dll.h
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
DLLIMPORT void HelloWorld();
#endif
项目名:testdll
生成结果:testdll.dll
python程序
#test dll
from ctypes import *
dll = CDLL("d:\\temp\\testdll.dll")
dll.HelloWorld()
测试结果