I found this blog post,
Simple Python ctypes Example, on
Reddit, and thought I’d see how different the procedure was for Windows.
What you’ll need:
Creating the DLL
Create a file dlltest.c with the following content:
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
multiply(int num1, int num2)
return num1 * num2;
Start the Visual Studio 2008 Command Prompt from the Start Menu (this sets up the path for the compiler and other files, which makes things easier) and go to the directory you saved dlltest.c to.
Compile it with the following command:
cl -LD dlltest.c -Fetest.dll
Testing the DLL
As in the original Linux example, this DLL is easily tested using similar commands:
>>> from ctypes import *
>>> libtest = cdll.LoadLibrary('test.dll')
>>> print libtest.multiply(2, 2)
So, that is the simplest DLL possible, I’ll look at (same as the original blog post) applying it to more complex examples later.