Pass C# string to eVC DLL (Part 2)

D

devgrt

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!
 
D

devgrt

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");
 

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