Why does Marshal Copy Stop After Unknown Character in C++/CLI?

  • Thread starter Thread starter GarrettT
  • Start date Start date
G

GarrettT

Guest
My apologies if this is in the wrong section; I'm unfamiliar with the layout of these forums.

I am attempting to copy a managed array into an unmanaged character array. Putting a watch on the contents of each of MyCharArray and ReadArray, I executed the following code:
char MyCharArray[100];
array<System::Byte> ^ReadArray = gcnew array<System::Byte>(73);
DataStream->Read(ReadArray, 0, pIx->MsgLen);
System::Runtime::InteropServices::Marshal::Copy ( ReadArray, 0, System::IntPtr(MyCharArray), 72).

Before the copy, MyCharArray is "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ" char*
&#2;" char*
After the copy, MyCharArray is
"¯¾ÞÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ&#2;" char*

Both before and after the copy, the contents of ReadArray is as follows:
175 '¯'; 190 '¾'; 173 '-'; 222 'Þ'; 13 ''; 208 'Ð'; 13 '-'; 240 'ð'; 1 '&#1;'; 0 ''; 0 ''; 0 '';

And so on. It's clear that the data ceases copying after reaching the value 13 at position 4, but I do not know why, nor how to prevent this behavior. If this behavior is unavoidable, which alternate methods are available that I could use? Thank you for any help you could provide.

Continue reading...
 
Back
Top