I have a following lines of code:
public static string getTrack1(string track1, int len)
{
IntPtr track1Ptr = UnsafeNativeMethods.Decrypt(track1, len);
Byte[] track1b = new Byte[200];
Marshal.Copy(track1Ptr, track1b, 0, track1b.Length);
return track1b.ToString();
}
deceleration of decrypt method is :
internal static class UnsafeNativeMethods
{
[DllImport(_dllLocation, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr Decrypt(string track1, int dataLen);
}
I am returning unsigned char* from visual c++ code and whenever i am calling the dll from c# code it always returns “System.Byte[]” instead of value. Am i doing something wrong here in marshal?
please help me here
You’re missing the transformation from byte[] to string, but you’ll have to define what’s the encoding. This may work:
But it would be better to do this;
If the encoding is Ansi (=Default)