How to wrap a existing DLL to a python module?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to wrap a existing DLL to a python module?

Bruce Who-2
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

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Reply | Threaded
Open this post in threaded view
|

Re: [Swig-user] How to wrap a existing DLL to a python module?

Stewart, Robert
From: "Bruce Who" <[hidden email]>
>
> 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.
[snip]
> 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.

Where is the DLL?  Is it on your path?

--
Rob Stewart                           [hidden email]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Reply | Threaded
Open this post in threaded view
|

Fwd: [Swig-user] How to wrap a existing DLL to a python module?

Bruce Who-2
---------- Forwarded message ----------
From: Bruce Who <[hidden email]>
Date: Apr 28, 2007 8:46 AM
Subject: Re: [Swig-user] How to wrap a existing DLL to a python module?
To: Rob Stewart <[hidden email]>


OMG, just call me dumb, I put the DLL to the same directory and it
works fine! Thanks!

On 4/27/07, Rob Stewart <[hidden email]> wrote:

> From: "Bruce Who" <[hidden email]>
> >
> > 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.
> [snip]
> > 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.
>
> Where is the DLL?  Is it on your path?
>
> --
> Rob Stewart                           [hidden email]
> Software Engineer                     http://www.sig.com
> Susquehanna International Group, LLP  using std::disclaimer;
>

Bruce

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Reply | Threaded
Open this post in threaded view
|

Re: How to wrap a existing DLL to a python module?

Bruce Who-2
In reply to this post by Bruce Who-2
Hi,

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
%inline{
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 <[hidden email]> 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.
>

Bruce

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Reply | Threaded
Open this post in threaded view
|

Re: [Swig-user] How to wrap a existing DLL to a python module?

wsfulton

Bruce Who wrote:

> Hi,
>
> 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
> %inline{
> 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.
>

Er, this is one of the things that SWIG is designed to do. Take a look
at %include.

William

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Reply | Threaded
Open this post in threaded view
|

Re: [Swig-user] How to wrap a existing DLL to a python module?

Bruce Who-2
Hi, William

Thanks! I have tried %include, and it works! This is my code:

%module pyTE
%include "TEVLib.h"

%inline %{
#include "TEVLib.h"

%}

and I find that the #include statement is necessary too, what's the
difference between %include and #include?


On 4/29/07, William S Fulton <[hidden email]> wrote:
>
>
> Er, this is one of the things that SWIG is designed to do. Take a look
> at %include.
>
> William
>

Bruce

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding