[C++-sig] How to wrap a existing DLL to a python module?

Bruce Who bruce.who.hk at gmail.com
Fri Apr 27 07:38:23 CEST 2007


Hi, all

I have a DLL and related .lib and .h files provided by 3rd party, and
I want to make a python extension module from this dll I tried swig
but failed.

At first , I just used this command:

swig -python -module TEVLib TEVLib.h

I got a TEVLib.py file, but it did not work of course. So I tried
another method: I wrote TEV.c and TEV.i, this TEV.c just wrappered all
functions from TEVLib and included all necessary .h files and also
included this statement

#pragma comment(lib, "TEVLib.lib")

Then I compiled all of these and got TEVLib.py and _TEVLib.pyd, but
when I tried to import it, error occured, it's said something like
that the DLL could not be imported.

I know that we can use ctypes to call functions in dll, but I just get
bored with defining function prototypes with CFUNCTYPE. That's why I
choose swig.

As a newbie, I just do not know why it doesnot work. Could somebody
help me out?Thanks in advance.


Bruce



More information about the Cplusplus-sig mailing list