I have a DLL with vanilla C functions implemented. I'd like these functions
to become wrappers for a managed object. So, I was thinking that the first
call would save a pointer statically to the managed object that future calls
could use. I found this:
http://msdn.microsoft.com/library/de...omixedmode.asp
and have implemented it to make sure the runtime is initialized. Now I have
strangeness. If I allocate the gcroot object on the stack, it works. If I
allocate the gcroot object on the heap or statically, I get exceptions.
static gcroot<GCPO::POAddr*> addr; // #1
int po_open()
{
addr = new GCPO::POAddr; // this crashes with
System.NullReferenceException in my dll
gcroot<GCPO::POAddr*> addr1;
addr1 = new GCPO::POAddr; // This WORKS
gcroot<GCPO::POAddr*>* addr2;
addr2 = new gcroot<GCPO::POAddr*>; // this crashes with
System.ExecutionEngineException in Unknown Module.
return 0;
}