I wrote a C ++ managed class that has the following function:
void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
{
strErrorMessage = (char*) Marshal::StringToHGlobalAnsi(_managedObject->GetLastError()).ToPointer();
}
As you can see, this is an easy way to copy the last error managed string to an unmanaged world ( char*).
From my unmanaged class, I call the method as follows:
char err[1000];
ofer->GetLastError(err);
Putting a breakpoint in a C ++ managed method indicates that the string has been successfully translated to char*. However, as soon as I return to the unmanaged class, the content err[1000]will be lost and empty again.
source
share