all groups > dotnet compact framework > january 2006 >
You're in the

dotnet compact framework

group:

Pass C# string to eVC DLL



Re: Pass C# string to eVC DLL Paul G. Tobey [eMVP]
1/31/2006 9:38:10 AM
dotnet compact framework: Fails how? C# strings, it should be clear, are always Unicode, not ASCII.
If you're counting on the string to consist of 8-bit characters, you're
wrong and it's probably showing you just the first character.

Paul T.

[quoted text, click to view]

Pass C# string to eVC DLL devgrt
1/31/2006 11:27:29 AM
I have an eVC DLL that I call from C#. I want to pass a C# string to the dll
and then copy that string's data into a char buffer as shown below. It
fails. Could anyone help me fix this code to what it should be. Thank you!

eVC DLL:
int mydll(LPSTR s)
{
char data[40];
strcpy(data, s);
}

C# calling the DLL:
[DllImport("MyCProcess.dll")]
public static extern int mydll(string s);
int r = mydll("teststring");

Re: Pass C# string to eVC DLL Chris Tacke, MVP
1/31/2006 12:18:53 PM
CE is unicode, so you shouldn't be using char, but instead either wchar_t or
the TCHAR macro, along with the right copy function.

-Chris

[quoted text, click to view]

AddThis Social Bookmark Button