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

dotnet compact framework

group:

Pass C# string to eVC DLL (Part 2)


Pass C# string to eVC DLL (Part 2) devgrt
1/31/2006 1:52:21 PM
dotnet compact framework:
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.

I tried a different method (from my last post) but something is still
wrong -- I only get two random characters instead of the whole string...

eVC DLL:
int fn1(char *s)
{
char *data = new char[40];
strcpy(data, s);
//data is not correct at this point
}

C# calling the DLL:
[DllImport("MyCProcess.dll")]
public static extern int fn1(byte [] s);
byte [] s = System.Text.Encoding.Unicode.GetBytes("this is a test string");
int r = fnl(s);

Thank for any help!

Re: Pass C# string to eVC DLL (Part 2) devgrt
1/31/2006 1:58:25 PM
OK -- I see the error:
I had:
byte [] s = System.Text.Encoding.Unicode.GetBytes("this is a test
string");
should be:
byte [] s = System.Text.Encoding.ASCII.GetBytes("this is a test string");

[quoted text, click to view]

AddThis Social Bookmark Button