cnd
cnd

Reputation: 33754

Convert usual char* from to cli array

I'm using C++ CLI. I need to convert usual char * to cli array. Here is what exactly I want :

unsigned char * b1 = (unsigned char *) &xp0[0];
unsigned char * b2 = (unsigned char *) &xp2[0];
unsigned char * b3 = (unsigned char *) &xp1[0];

array<byte>^ a1 = gcnew array<byte>(928); //a1 = b1;
array<byte>^ a2 = gcnew array<byte>(928); //a2 = b2;
array<byte>^ a3 = gcnew array<byte>(232); //a3 = b3;

//FBOI::Lambda::SetP(numSF,a1,a2,a3);

What is the easiest way to convert char * to cli byte array with single dimension?

Upvotes: 2

Views: 3829

Answers (1)

ali_bahoo
ali_bahoo

Reputation: 4863

Use Marshal::Copy() like:

Marshal::Copy(IntPtr(source_addr ), dest_array, start_index, length);

Marshal::Copy(IntPtr( b1 ), a1, 0, a1->Length);

Upvotes: 4

Related Questions