1.Test.h
#ifndef TEST_INTADD_HEADER #define TEST_INTADD_HEADER extern "C" int WINAPIV IntAdd(int a,int b); #endif
2.Test.cpp
#include <windows.h> #include "Test.h" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpReserved) { UNREFERENCED_PARAMETER(hinstDLL); UNREFERENCED_PARAMETER(lpReserved); switch(fdwReason) { case DLL_PROCESS_ATTACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; } return TRUE; } extern "C" int WINAPIV IntAdd(int a,int b) { return a+b; }
3.Test.def
LIBRARY "Test" EXPORTS IntAdd
4.test_cdll.py
#test_cdll.py #请用__cdecl调用约定而不是__stdcall from ctypes import * fileName="Test.dll" Test=cdll.LoadLibrary(fileName) print(Test.IntAdd(2,3))