Copying data from unmanaged to managed
-
Hi, I am trying to copy data from a structure
typedef struct OctetString { unsigned int length; unsigned char *value; } OctetString;
I have only managed to copy the value using a for-loop and an ArrayListOctetString* data; ArrayList^ bits = gcnew ArrayList(); for(unsigned int i=0;i<data->length;i++) { bits->Add((char)*data->value); data->value++; }
My question is: Is there a better way to copy the data into the ArrayList, and is there a more suitable structure than a ArryList to handle binary data of different lengths? /krissi -
Hi, I am trying to copy data from a structure
typedef struct OctetString { unsigned int length; unsigned char *value; } OctetString;
I have only managed to copy the value using a for-loop and an ArrayListOctetString* data; ArrayList^ bits = gcnew ArrayList(); for(unsigned int i=0;i<data->length;i++) { bits->Add((char)*data->value); data->value++; }
My question is: Is there a better way to copy the data into the ArrayList, and is there a more suitable structure than a ArryList to handle binary data of different lengths? /krissiYou could use an equivalent value class :-
value class MOctetString
{
unsigned int length;
array<unsigned char>^ value;
};Regards, Nish
Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
Currently working on C++/CLI in Action for Manning Publications. (*Sample chapter available online*) -
Hi, I am trying to copy data from a structure
typedef struct OctetString { unsigned int length; unsigned char *value; } OctetString;
I have only managed to copy the value using a for-loop and an ArrayListOctetString* data; ArrayList^ bits = gcnew ArrayList(); for(unsigned int i=0;i<data->length;i++) { bits->Add((char)*data->value); data->value++; }
My question is: Is there a better way to copy the data into the ArrayList, and is there a more suitable structure than a ArryList to handle binary data of different lengths? /krissi -
kristmun wrote:
Is there a better way to copy the data into the ArrayList, and is there a more suitable structure than a ArryList to handle binary data of different lengths?
They hide that information in the documentation[^]
led mike
Hi guys, thanks for the advice. It works now using the Copy method
array<unsigned char>^ value = {'a','b','c'}; char* ptr = new char[value->Length]; Marshal::Copy(value,0,(IntPtr)ptr,value->Length);
and the other way aroundint length = 3; char str[] = {'d','e','f'}; char* pStr = &str[0]; array<unsigned char>^ strArr = gcnew array<unsigned char>(length); Marshal::Copy((IntPtr)pStr,strArr,0,length);
I didn't quite get the value class way :sigh: