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

Bruce Who bruce.who.hk at gmail.com
Sat Apr 28 03:39:47 CEST 2007


Another question, what i do now is wrap all functions in DLL again like this:

// this is header file for DLL
void func(void)

// this is my .cpp file for swig
#pragma comment(lib, "TEVlib.lib")

void _func(void)
    func() // this is the func of DLL

// this is .i file
extern void _func(void);

I just wonder if it is possible that we can generate a .py file
directly from the header file of DLL with all functions exposed? I
think that can save a lot of time. I have tried without success.

On 4/27/07, Bruce Who <bruce.who.hk at gmail.com> wrote:
> 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.


More information about the Cplusplus-sig mailing list