Click to See Complete Forum and Search --> : Problem calling unmanaged C++ Library from C# through managed wrapper


Cabadam
April 11th, 2004, 01:23 PM
I have an unmanaged C++ library that I need to use through C#. I created a Managed C++ class library and through it wrote a wrapper class to call what I need.
However, one of the methods (an Initialize function in the unmanaged library) crashes everytime I call it. Initialize calls another function 'GetInstance' (a static member function of a class) which looks something like:


CLibConfig& CLibConfig::GetInstance()
{
//Our instance (to avoid singleton problems!)
static CLibConfig sInstance; <--------

//Return it
return sInstance;
}

It is on the static sInstance line that I get a debug assertion:
dbheap.c, Line1291.
_CrtIsValidHeapPointer(pUserData).

The static line is the last line from the call stack within the C++ library, from there it goes into the C runtime. This code works just fine when called from a native C++ application. Any suggestions?