String from unmanaged DLL to managed app

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
 
G

Guest

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
 
M

Markus Forrer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top