Windows dll example?
Sandy Norton
sandskyfly at hotmail.com
Mon Dec 16 23:11:54 EST 2002
Jive Dadson wrote in message
> I need to make a Python extension using MS VC++, preferably using a dll.
Not exactly what you need, but Thomas Heller's recently released
ctypes module is a v. cool way of getting at those dlls without having
to learn the python API (Pyrex is another cool way, of course)
Here's a very simple example of how to go about it. It assumes
windows,
MS VC++, and that you've already installed ctypes
[http://starship.python.net/crew/theller/ctypes.html].
1. create your simple dll, call it "xdll.cpp":
#define EXPORT extern "C" __declspec(dllexport)
EXPORT int add(int x, int y) {
return x + y;
}
2. compile it:
prompt> cl /LD xdll.cpp
3. Test it with the following python module "test_xdll.py":
from ctypes import cdll
print cdll.xdll.add(10, 100)
That's it.
enjoy,
Sandy
More information about the Python-list
mailing list