Click to See Complete Forum and Search --> : Passing std::string to constructor of unmanaged class


svkr2k
July 12th, 2005, 01:33 AM
Dear forum members,

I have an unmanaged dll (written in VC++ 6.0) that implements a class CUnmanaged. The class has the following constructor:

CUnmanaged::CUnmanaged( const std::string& filename )
{
/* ... */
}

I have a client application (written in VC++ .Net) that uses the above class dll as follows:

CUnmanaged* oserr = new CUnmanaged("error.out");

When the above line is executed, an assertion dialog is popped up:
"An unhandled exception of type 'System.NullReferenceException' occurred in MyUnmanaged.dll
Additional information: Object reference not set to an instance of an object."

Can anyone tell me what is wrong with the code ? and how to solve the problem ?
Thanks in advance.
-Rajesh.

NoHero
July 12th, 2005, 06:18 AM
Maybe you are causing an error in your constructor but likely try this:

CUnmanaged *oserr = __nogc new CUnmanaged("error.out");

Andreas Masur
July 12th, 2005, 07:11 AM
PRB: Access Violation When Accessing STL Object in DLL (http://support.microsoft.com/kb/q172396/)