Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Copying data from unmanaged to managed

Copying data from unmanaged to managed

Scheduled Pinned Locked Moved Managed C++/CLI
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kristmun
    wrote on last edited by
    #1

    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 ArrayList OctetString* 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

    N L 2 Replies Last reply
    0
    • K kristmun

      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 ArrayList OctetString* 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

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      You 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*)

      1 Reply Last reply
      0
      • K kristmun

        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 ArrayList OctetString* 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

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        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

        K 1 Reply Last reply
        0
        • L led mike

          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

          K Offline
          K Offline
          kristmun
          wrote on last edited by
          #4

          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 around int 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:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups