Problem in Accessing C++ Class Instance Global Variable (near success, help please!!)
BPettersen at NAREX.com
Fri Apr 18 11:01:07 CEST 2003
> 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
> 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
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
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
More information about the Python-list