example code to access some C++ classes in a DLL

Jimmy Retzlaff jimmy at retzlaff.com
Sun Feb 29 05:35:47 CET 2004


Larry Bates wrote:

>> i have written a DLL that implements some C++ classes and
>> their methods.  Now i would like to make the classes and
>> their methods known to python.
>
> You can interface Python to ANY .DLL by using
> CALLDLL.  I've written a wrapper that I feel makes
> doing this easier that is posted at:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146847

Thomas Heller's ctypes also makes calling most DLLs very simple, but
neither of these approaches are well suited to using classes and methods
in C++ DLLs. C++ compilers do name mangling (i.e., they tack extra
symbols onto function names) to implement function overloading. You'd
have to look up the mangling to figure out what to call and this
mangling often differs between different compilers and sometimes between
different versions of the same compiler. Name mangling (and hence
function overloading) can be turned off in some (all?) C++ compilers for
normal functions, but I'm not sure name mangling can be disabled for
methods (which typically have their classes encoded into their names).

Jimmy





More information about the Python-list mailing list