Encoding question.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am sending strings from C# to a third party unmanaged code written in C.
Signature of one of the methods in the unmanaged code is

SomeMethod(char *name, char *value)

Currently, I am converting the string in to byte array and passing the
byte[] to
this method. My current code is,

string str = "Some-Name";
byte[] n = UTF8Encoding.GetBytes(str);
str = "Some-Value";
byte[] v = UTF8Encoding.GetBytes(str);
SomeMethod(n,v);

My current, DLLImport method decleration is:
SomeMethod(byte[] name, byte[] val);

Method Signature in unmanaged code is :
SomeMethod(char *name, char *val);

Is my procedure correct. Is there any better way for sending strings to a
method
in unmanaged code writtent in C that expects pointers to strings ?
Kindly let me know. I'm using C#, Compact Framework.

Cheers,

Naveen.
 
not quite actually, some-times I am getting error message saying
"String was illegally UTF-8 encoded"(I'm assuming it is a third party error
message).
I have tried declaring "SomeMethod(string name, string val), then only the
first character in the "name" and "val" strings are being accepted by the
unmanaged code.

Thats why I'm wondering my procedure is correct or not.

Cheers,
Naveen.

Chris Tacke said:
It looks fine offhand. Is it working?

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


Naveen Mukkelli said:
Hi,

I am sending strings from C# to a third party unmanaged code written in
C.
Signature of one of the methods in the unmanaged code is

SomeMethod(char *name, char *value)

Currently, I am converting the string in to byte array and passing the
byte[] to
this method. My current code is,

string str = "Some-Name";
byte[] n = UTF8Encoding.GetBytes(str);
str = "Some-Value";
byte[] v = UTF8Encoding.GetBytes(str);
SomeMethod(n,v);

My current, DLLImport method decleration is:
SomeMethod(byte[] name, byte[] val);

Method Signature in unmanaged code is :
SomeMethod(char *name, char *val);

Is my procedure correct. Is there any better way for sending strings to a
method
in unmanaged code writtent in C that expects pointers to strings ?
Kindly let me know. I'm using C#, Compact Framework.

Cheers,

Naveen.
 
Back
Top