N
Neil
I am developing a demo in C# using Managed DirectX. I wanted to use a
C++ static library in the demo (its a class for handling physics), so
I decided to create my Graphics classes in C#, inherit from them in
MC++. So far so good......
I modified my MC++ project to run as mixed mode (removed nochkclr.obj,
added msvcrt.lib, etc etc), and created 2 unmanaged classes which
handled the calls to the static lib (btw all the code works fine in
other unmanaged C++ projects - i just copied it straight out) . I then
created managed wrappers around them. Again so far so good......
BUT THEN!
When I try and call the code from C++ it falls over. I get a null
object exception. Now my unmanaged classes use some static members,
and if I remove the calls to static member variables it all runs OK -
obviously it doesnt do what I want, but at least it doesnt crash. If I
put them back in it fails.
I debugged the code to see if my suspicions were right - it seems the
static members are being reset - eg (c#)(btw these arent my class
names - changed for clarity)
MyGFXSys mgfxs= new MyGfxSys(); //calls unmanaged constructor in
here which initialises static members - shows in the debugger fine.
MyGFXObject obj3d = new MyGFXObject() //calls unmanaged constructor
in here which accesses the static member from above. This call fails -
static members variables appear un-initialised.
The static members I refer to are part of the UNMANAGED class btw, in
case that makes a difference. I also tried making them (ugh) global,
and got the same effect.
OK, I know what I'd be thinking about now - why not find another way
to do it without static members or globals? Unfortunately the static
lib makes use of these, and I dont have and cant get the source for
this - so I need to solve this.
Any ideas, help, or simply prayers would be much appreciated.
Cheers
Neil
C++ static library in the demo (its a class for handling physics), so
I decided to create my Graphics classes in C#, inherit from them in
MC++. So far so good......
I modified my MC++ project to run as mixed mode (removed nochkclr.obj,
added msvcrt.lib, etc etc), and created 2 unmanaged classes which
handled the calls to the static lib (btw all the code works fine in
other unmanaged C++ projects - i just copied it straight out) . I then
created managed wrappers around them. Again so far so good......
BUT THEN!
When I try and call the code from C++ it falls over. I get a null
object exception. Now my unmanaged classes use some static members,
and if I remove the calls to static member variables it all runs OK -
obviously it doesnt do what I want, but at least it doesnt crash. If I
put them back in it fails.
I debugged the code to see if my suspicions were right - it seems the
static members are being reset - eg (c#)(btw these arent my class
names - changed for clarity)
MyGFXSys mgfxs= new MyGfxSys(); //calls unmanaged constructor in
here which initialises static members - shows in the debugger fine.
MyGFXObject obj3d = new MyGFXObject() //calls unmanaged constructor
in here which accesses the static member from above. This call fails -
static members variables appear un-initialised.
The static members I refer to are part of the UNMANAGED class btw, in
case that makes a difference. I also tried making them (ugh) global,
and got the same effect.
OK, I know what I'd be thinking about now - why not find another way
to do it without static members or globals? Unfortunately the static
lib makes use of these, and I dont have and cant get the source for
this - so I need to solve this.
Any ideas, help, or simply prayers would be much appreciated.
Cheers
Neil