Problem in Accessing C++ Class Instance Global Variable (near success, help please!!)

Alan Pong alanpong at hkstar.com
Fri Apr 18 08:40:47 EDT 2003


1. i did used Py_InitModule.
2. correction: wrapper.cpp compiled to wrapper.obj which is linked to
form myext1.dll.   test.exe doesn't contain wrapper.obj
3.  sorry i don't understand fix2 and fix3 mentioned below.

4. i re-think about: can i access a global variable like this???? ...

any sample code please?


"Bjorn Pettersen" <BPettersen at NAREX.com> wrote in message news:<mailman.1050656618.32150.python-list at python.org>...
> > From: Alan Pong [mailto:alanpong at hkstar.com] 
> > 
> > python 2.3, vc++6, win32 exe project
> > 
> > I has one global c++ class instance variable.  I want to call its
> > member
> > function through wrapper function which is accessed by python.
> > However, as seen in wrapper.cpp, it give me another new variable copy
> > so that phython actually accessing another instance.
> 
> First, PyImport AddModule( "myext1" ), doesn't load the module, but
> returns either an empty module or a module "myext1" that had allready
> been loaded. It returns a PyObject that you're supposed to do something
> with :-)
> 
> The symptoms imply that your "library" (wrapper.cpp) is most likely
> compiled statically against both your program (test.exe) and your dll
> (myext1.cpp). I.e. the dll is calling a method on an object that is
> "named" the same but exists in the dll memory space, while your
> application is reading an object (same "name") but in the executable's
> namespace. Try extending the dll to read back the value from its object
> to verify.
> 
> fix1: "Don't do that" <wink>.
> fix2: pass the object as an argument.
> fix3: make the object available through a module object both parties can
> "import" (meaning you'll need the PyRun * functions that take
> namespaces.
> 
> -- bjorn




More information about the Python-list mailing list