N
nicewenyan
I want to pass a managed c# byte (8 bit) array into a unmanaged c++
function:
extern "C" void AddData(unsigned int* data);
I use P/Invoke on managed side to do the marshaling as following:
[DllImport("Test.dll", EntryPoint = "AddData")]
public static extern int AddData(IntPtr data);
byte[] a = new byte[] { 44, 55, 66};
IntPtr temp = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(byte)) *
a.Length);
Marshal.Copy(a, 0, temp, a.Length);
AddData(temp);
Marshal.FreeCoTaskMem(temp);
But when I debug into unmanaged function, I couldn't get correct data,
I must miss something basic. The reason I want to test this is because
later I'll have complicated structures containing byte array as member
variable, and if this works, I can use similar IntPtr inside structure
to pass it into unmanaged side.
I appreciate any help, thanks.
function:
extern "C" void AddData(unsigned int* data);
I use P/Invoke on managed side to do the marshaling as following:
[DllImport("Test.dll", EntryPoint = "AddData")]
public static extern int AddData(IntPtr data);
byte[] a = new byte[] { 44, 55, 66};
IntPtr temp = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(byte)) *
a.Length);
Marshal.Copy(a, 0, temp, a.Length);
AddData(temp);
Marshal.FreeCoTaskMem(temp);
But when I debug into unmanaged function, I couldn't get correct data,
I must miss something basic. The reason I want to test this is because
later I'll have complicated structures containing byte array as member
variable, and if this works, I can use similar IntPtr inside structure
to pass it into unmanaged side.
I appreciate any help, thanks.