Copying from unsigned char * to the CString
-
Hi All, I have unsigned char * buffer in which some data are stored , now I want to move these all data to my CString variable for some operations. I tried to copy but problem is that in my unsigned char * some data are padded as zero, So I hope that in CString it gets the null value so it can not copy whole data. I tried to copy from unsigned char * to the CString using... CString tmpMsg = CString(msg); // Here msg is the unsigned char *
Ashish Bhatt
-
Hi All, I have unsigned char * buffer in which some data are stored , now I want to move these all data to my CString variable for some operations. I tried to copy but problem is that in my unsigned char * some data are padded as zero, So I hope that in CString it gets the null value so it can not copy whole data. I tried to copy from unsigned char * to the CString using... CString tmpMsg = CString(msg); // Here msg is the unsigned char *
Ashish Bhatt
-
Hi All, I have unsigned char * buffer in which some data are stored , now I want to move these all data to my CString variable for some operations. I tried to copy but problem is that in my unsigned char * some data are padded as zero, So I hope that in CString it gets the null value so it can not copy whole data. I tried to copy from unsigned char * to the CString using... CString tmpMsg = CString(msg); // Here msg is the unsigned char *
Ashish Bhatt
-
Thanks ... I used memcpy() as u told me, But I used like ........ memcpy(&tempMsg,(unsigned char*)msg,noOfBytes); Then it gives me the run time Access violation error as below... TestRTMP.exe: 0xC0000005: Access violation reading location 0x49468964. So,plz help me , is there any other way to copying.
Ashish Bhatt
-
Thanks ... I used memcpy() as u told me, But I used like ........ memcpy(&tempMsg,(unsigned char*)msg,noOfBytes); Then it gives me the run time Access violation error as below... TestRTMP.exe: 0xC0000005: Access violation reading location 0x49468964. So,plz help me , is there any other way to copying.
Ashish Bhatt
Does not surprise me that it gives you an access violation when doing that. The first and foremost rule to remember is: DO NOT USE MEMCPY ON CLASSES. Classes work independently, managing their own memory and so on. Therefore, you should use the exposed interfaces in the classes to do stuff. In this case, you're overwriting important data in the class, not to mention that the class's internal buffer is nowhere large enough to hold your data. As mentioned, use CString.GetBuffer(LengthOfBuffer). It returns a pointer to a buffer. Copy data using memcpy/CopyMemory. Then call CString.ReleaseBuffer(LengthOfData). That should do the trick.
-
Hi All, I have unsigned char * buffer in which some data are stored , now I want to move these all data to my CString variable for some operations. I tried to copy but problem is that in my unsigned char * some data are padded as zero, So I hope that in CString it gets the null value so it can not copy whole data. I tried to copy from unsigned char * to the CString using... CString tmpMsg = CString(msg); // Here msg is the unsigned char *
Ashish Bhatt
The
CString
class is designed to handle C-style strings, meaning strings that are terminated with a character value of zero (AKANUL
). It is not designed to handle raw data that contains embeddedNUL
characters, not double-NUL
-terminated collections of strings. Sounds like you may be abit
too comfortable withCString
s... :)-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles