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