I'm having trouble Marshaling a CString from C++ to C#.
My C++ exported function is:
EXPORT_DLL char* getJavascript(){
*jsArray = const_cast<char*> ( pWindow->returnJS().c_str () );
cerr << "string is: " << const_cast<char*> ( pWindow->returnJS().c_str () ) << "!" << endl; // output to log file...
//*jsArray = "this is a test";
return jsArray[0] ;
}
My C# function is:
[DllImport ("DLL_Plugin")]
private static extern IntPtr getJavascript();
//.......
void updateJS(){
jsString = Marshal.PtrToStringAnsi(getJavascript());
}
If I uncomment (//*jsArray = "this is a test";) from the first block, the string is passed just fine and it appears in C# as it should.
Also, the cerr line writes the string to a log file with no problem, so I think this is a problem with the way C# receives the string? I'm not sure. Any help would be appreciated.