Need help on calling user DLL functions from wxPython

Hi Robin,

I added %include my_typemaps.i in the .i file and specified the necessary path for -I flag while running the SWIG. But this gives error "Access denied" and does not generate the .cxx file.

Regards,
Gauri

···

From: Robin Dunn <robin@alldunn.com>
Reply-To: wxPython-users@lists.wxwindows.org
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] Need help on calling user DLL functions from wxPython
Date: Fri, 17 Oct 2003 10:37:58 -0700

Hi Gauri,

Sorry I didn't answer your other messages earlier, I've been very busy.

Gauri Deshpande wrote:

Hi,

Our project requirement is to support scripting facility such that the wxPython script file is able to call the functions from a DLL which is written in C++ using wxWindows.

We are trying out some sample code to check for above feature. For this, we have created a sample wxWindows dll which exports a function. Using SWIG we are now able to call the DLL exported function from wxPython. But wxPython gives error if the exported function prototype uses wxWindows datatypes like wxstring. We are not
able to figure out the reason behind this error.

You need to teach swig how to convert wxString to a Python string. Since wxPython already does this you can do it simply by using "%include my_typemaps.i" and adding the wxPython/src dir to your -I flags that you give when running SWIG.

Another requirement of our project is to call wxPython script from our wxWindows application.

The samples/embedding sample explains how this can be done. I have created a sample application and added embedded.cpp file to it. But this application crashes. I tried to debug the application and found that the statement main_tstate = wxPyBeginAllowThreads() crashes. I also observed that in the function wxPyCoreAPI_IMPORT of wxPython.h the variable wxPyCoreAPIPtr is assigned a NULL value by the call (wxPyCoreAPI*)PyCObject_Import("wxc", "wxPyCoreAPI").

Can anyone please tell me the possible reason behind this crash? Am I
missing out some important step?

Trace into the PyCObject_Import to find out why. My guess is that it is simply unable to import the module. Perhaps PYTHONPATH problems, or if you are using a debug build of your program and Python it is unable to find a debug version of the wxPython module (named wxc_d.pyd.)

I have been through the link you have mentioned. The example they
have given uses wxSwig. I have used Swig. Is it so that swig is
unable to recognize wxWindows datatypes ?

No, it is so the runtime code generated by swig is compatible with what wxPython uses. (wxSWIG is based on an old version of swig that has had several non-standard patches done to it.) You probably noticed that some of the APIs exported by wxPyCoreAPI_IMPORT are SWIG funcitons. This is so all the extension modules use the same SWIG runtime without requiring a separate DLL. So your swig generated module will also need to do #include "wxPython.h" and it will automatically do the wxPyCoreAPI_IMPORT when the module is imported.

Also if I am supposed to
use wxSwig, are you aware from where this could be downloaded ?

It is in the wxWindows CVS in wxWindows/wxPython/wxSWIG. If you don't want to use CVS then you can get wxSWIG also from the wxWindows CVS snapshots. The rest of the code is for wxWindows/wxPython 2.5.x, but the wxSWIG there is identical with what is used for 2.4. http://wxwindows.org/snapshots/

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

_________________________________________________________________
Make fun prints Click here to order. http://www.kodakexpress.co.in Delivery anywhere in India.

Gauri Deshpande wrote:

Hi Robin,

I added %include my_typemaps.i in the .i file and specified the necessary path for -I flag while running the SWIG. But this gives error "Access denied" and does not generate the .cxx file.

Does it say what it is trying to access that has been denied?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

I am getting the "Access Denied" error too, when I add %include
my_typemaps.i in the .i file and specify the necessary path for -I flag
while running the SWIG.
This is the only error message displayed. It does not specify to what
Access is Denied.
Could you throw some light on this ?

Thanks,
Shruti

···

----- Original Message -----
From: Robin Dunn <robin@alldunn.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Tuesday, October 21, 2003 6:22 AM
Subject: Re: [wxPython-users] Need help on calling user DLL functions
fromwxPython

Gauri Deshpande wrote:
> Hi Robin,
>
> I added %include my_typemaps.i in the .i file and specified the
> necessary path for -I flag while running the SWIG. But this gives error
> "Access denied" and does not generate the .cxx file.

Does it say what it is trying to access that has been denied?

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Shruti Mahambre wrote:

Hi Robin,

I am getting the "Access Denied" error too, when I add %include
my_typemaps.i in the .i file and specify the necessary path for -I flag
while running the SWIG.
This is the only error message displayed. It does not specify to what
Access is Denied.
Could you throw some light on this ?

No.

What is the exact SWIG command line you use? And the complete output?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

1. I have created a dll in wxWindows called "trial".
2. I have exported a class CTrial, which contains a function foo3() which
returns a wxString.
3. I have included my_typemaps.i in trial.i
4. Trial.i is as follows :
/********* Trial.i *****************************/
%module trial
%{
#include "trial.h"
#ifdef __WXMSW__
#include <windows.h>
#endif

%}
%pragma(python) code = "import wx"
%{
    static const wxString wxPyEmptyString(wxT(""));
%}
%include my_typemaps.i
extern int wxEntry(void *p);
extern "C" class CTrial {
public:
  int a;
  CTrial(void)
  {
    a=10;
  };

  int foo1(char *str) {
    int* p = new int;
    wxString wstr = str;
    if (wstr == "abc")
        return 10;
    else
        return 20;
  }
int foo2 (int x1, int x2);
wxString foo3();
};

/****************************************/

5. The following is the command / output I get at the command prompt when
running Swig.
/***************************************/
E:\Python23\Trial>C:\SWIG-1.3.19\swig -python -c++ -I<E:\PythonSource\wxPyth
onSc-2.4.2.4\wxPython\src> trial.i
Access is denied.
/***************************************/
6. If I dont provide the -I option along with the path of Python Srouce, I
get the following error at command prompt :
trial.i:13: Unable to find 'my_typemaps.i'

I hope this information helps.
Thanks,
Shruti

···

---- Original Message -----
From: Robin Dunn <robin@alldunn.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Tuesday, October 21, 2003 9:45 PM
Subject: Re: [wxPython-users] Need help on calling user DLL functions
fromwxPython

Shruti Mahambre wrote:
> Hi Robin,
>
> I am getting the "Access Denied" error too, when I add %include
> my_typemaps.i in the .i file and specify the necessary path for -I flag
> while running the SWIG.
> This is the only error message displayed. It does not specify to what
> Access is Denied.
> Could you throw some light on this ?
>

No.

What is the exact SWIG command line you use? And the complete output?

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Hi Robin

I am attaching the code files for your reference. I have been using a
Release build for my work.

Thanks,
Shruti

Code.zip (402 KB)

···

----- Original Message -----
From: Shruti Mahambre <shruti@jopasana.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Wednesday, October 22, 2003 12:25 PM
Subject: Re: [wxPython-users] Need help on calling user DLL functions
fromwxPython

Hi Robin,

1. I have created a dll in wxWindows called "trial".
2. I have exported a class CTrial, which contains a function foo3() which
returns a wxString.
3. I have included my_typemaps.i in trial.i
4. Trial.i is as follows :
/********* Trial.i *****************************/
%module trial
%{
#include "trial.h"
#ifdef __WXMSW__
#include <windows.h>
#endif

%}
%pragma(python) code = "import wx"
%{
    static const wxString wxPyEmptyString(wxT(""));
%}
%include my_typemaps.i
extern int wxEntry(void *p);
extern "C" class CTrial {
public:
  int a;
  CTrial(void)
  {
    a=10;
  };

  int foo1(char *str) {
    int* p = new int;
    wxString wstr = str;
    if (wstr == "abc")
        return 10;
    else
        return 20;
  }
int foo2 (int x1, int x2);
wxString foo3();
};

/****************************************/

5. The following is the command / output I get at the command prompt when
running Swig.
/***************************************/

E:\Python23\Trial>C:\SWIG-1.3.19\swig -python -c++ -I<E:\PythonSource\wxPyth

onSc-2.4.2.4\wxPython\src> trial.i
Access is denied.
/***************************************/
6. If I dont provide the -I option along with the path of Python Srouce, I
get the following error at command prompt :
trial.i:13: Unable to find 'my_typemaps.i'

I hope this information helps.
Thanks,
Shruti

---- Original Message -----
From: Robin Dunn <robin@alldunn.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Tuesday, October 21, 2003 9:45 PM
Subject: Re: [wxPython-users] Need help on calling user DLL functions
fromwxPython

> Shruti Mahambre wrote:
> > Hi Robin,
> >
> > I am getting the "Access Denied" error too, when I add %include
> > my_typemaps.i in the .i file and specify the necessary path for -I

flag

> > while running the SWIG.
> > This is the only error message displayed. It does not specify to what
> > Access is Denied.
> > Could you throw some light on this ?
> >
>
> No.
>
> What is the exact SWIG command line you use? And the complete output?
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Shruti Mahambre wrote:

5. The following is the command / output I get at the command prompt when
running Swig.
/***************************************/
E:\Python23\Trial>C:\SWIG-1.3.19\swig -python -c++ -I<E:\PythonSource\wxPyth
onSc-2.4.2.4\wxPython\src> trial.i
Access is denied.

First, don't put the include dir inside of <>, it thinks you are trying
to redirect input from a directory, which is illegal.

Second. You can't currently use SWIG 1.3.19 with wxPython. You need to
use my patched up version of the old swig, known as wxSWIG. It is
located in the wxWindows CVS (or in CVS snapshots) in
wxWindows/wxPython/wxSWIG. I've explained why and how in recent
messages to the list.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!