String from unmanaged DLL to managed app

  • Thread starter Thread starter Markus Forrer
  • Start date Start date
M

Markus Forrer

On Windows CE 5.0 and CF2.0 a try to send a string from a unmanaged DLL to
managed app:

extern "C" __declspec(dllexport) void GetError(char *pErrorMessage)
{
strcpy(pErrorMessage, "Hello C# World!");
}



[DllImport("TestDll.dll")]
internal static extern void GetError([MarshalAs(UnmanagedType.LPStr)]
StringBuilder errorMessage);

StringBuilder message = new StringBuilder(500);
GetError(message );

I allways get an error 'NotSupportedException'.

Thanks for help!
Markus
 
CE is Unicode, so change that to use Unicode strings..

extern "C" __declspec(dllexport) void GetError(TCHAR *pErrorMessage)
{
_tcscpy(pErrorMessage, _T("Hello C# World!"));
}

-Chris
 
CE is Unicode, so change that to use Unicode strings..

....and I also had to remove 'MarshalAs'! Now it works, thank you very much!
Markus
 
Back
Top