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. Problem in converting Unmanaged C++ Code to Managed C++ Code

Problem in converting Unmanaged C++ Code to Managed C++ Code

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++data-structures
2 Posts 2 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.
  • S Offline
    S Offline
    sunil4400
    wrote on last edited by
    #1

    Hello all, I have a strucure as given below. public ref struct PASSTHRU_MSG { unsigned long ulProtocolID; unsigned long ulRxStatus; unsigned long ulTxFlags; unsigned long ulTimeStamp; unsigned long ulDataSize; unsigned long ulExtraDataIndex; array ^ucData;//[4128]; }; PASSTHRU_MSG ^passThruMsg = gcnew PASSTHRU_MSG; In Unmanaged Code we used to access the passThruMsg object of this type as (unsigned char*). There we did not encounter any problem. But now in Managed Code I'm supposed to convert passThruMsg object to array^) or (String^). But I'm unable to convert it to either of the above mentioned forms. I'm getting Compilation warning, and a runtime crash. So, now I'm thinking of filling the data contained in the passThruMsg object to a (String^) or an (array^). The issue with (String^) is String::Copy() doesn't work if it encounters a null character. Please give me an advice which one to use. Thanks in advance. Regards Sunil

    2 1 Reply Last reply
    0
    • S sunil4400

      Hello all, I have a strucure as given below. public ref struct PASSTHRU_MSG { unsigned long ulProtocolID; unsigned long ulRxStatus; unsigned long ulTxFlags; unsigned long ulTimeStamp; unsigned long ulDataSize; unsigned long ulExtraDataIndex; array ^ucData;//[4128]; }; PASSTHRU_MSG ^passThruMsg = gcnew PASSTHRU_MSG; In Unmanaged Code we used to access the passThruMsg object of this type as (unsigned char*). There we did not encounter any problem. But now in Managed Code I'm supposed to convert passThruMsg object to array^) or (String^). But I'm unable to convert it to either of the above mentioned forms. I'm getting Compilation warning, and a runtime crash. So, now I'm thinking of filling the data contained in the passThruMsg object to a (String^) or an (array^). The issue with (String^) is String::Copy() doesn't work if it encounters a null character. Please give me an advice which one to use. Thanks in advance. Regards Sunil

      2 Offline
      2 Offline
      2bee
      wrote on last edited by
      #2

      Hi Sunil, you could try one of these structs public ref struct PASSTHRU_MSG { unsigned long ulProtocolID; unsigned long ulRxStatus; unsigned long ulTxFlags; unsigned long ulTimeStamp; unsigned long ulDataSize; unsigned long ulExtraDataIndex; static array ^ ucData = gcnew array (4128); }; or public ref struct PASSTHRU_MSG { PASSTHRU_MSG() { ucData = gcnew array (DATA_SIZE); } unsigned long ulProtocolID; unsigned long ulRxStatus; unsigned long ulTxFlags; unsigned long ulTimeStamp; unsigned long ulDataSize; unsigned long ulExtraDataIndex; array ^ ucData; private: literal int DATA_SIZE = 4128; }; regards Tobias

      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