I have tried to convert a CString To BYTE*` and "BYTE* to CByteArray" in MFC, With Your Suggestions The CString Has Been Converted To BYTE*. But I'm not able to Convert The Entire Byte* To CByteArray It Returns Partial Data With Some Garbage Values.
I Described My Actual Problem Here...
The code:
CString csData =_T("someData");
BYTE *pByteArray = (PBYTE)(LPCTSTR)csData.GetBuffer();
CString str;
str=LPTSTR(pByteArray);
AfxMessageBox(str); //returns "someData"
CByteArray arrByte2;
arrByte2.SetSize(csData.GetLength()+1);
memcpy(arrByte2.GetData(), pByteArray, csData.GetLength()+1);
CString text((LPTSTR)arrByte2.GetData(),arrByte2.GetSize());
CStringA result(text);
AfxMessageBox(text);//returns "some﵄﷽ꮫꮫ"
BYTE*. Your real issue is, that you later fail to interpret that data appropriately. Besides,GetBuffer()is the wrong call (for one, it requires that you callReleaseBuffer()later on). What you meant to call is GetString instead. - IInspectable