QueryBinaryValue to CByteArray
-
I have the following code:
CRegKey reg; CString sData; CByteArray arrByte; ULONG nLength = 0; if (ERROR\_SUCCESS == reg.Open(HKEY\_CURRENT\_USER, sKeyName, KEY\_READ) && ERROR\_SUCCESS == reg.QueryBinaryValue(sValueName, arrByte.GetData(), &nLength)) { sData = CString((LPCTSTR)arrByte.GetData(), arrByte.GetSize()); }
the code is running on sData = ... nLength has 10 value, sData is empty, arrByte has 0 size ... what I am missing here ? Of course, in that registry location I have data ...
-
I have the following code:
CRegKey reg; CString sData; CByteArray arrByte; ULONG nLength = 0; if (ERROR\_SUCCESS == reg.Open(HKEY\_CURRENT\_USER, sKeyName, KEY\_READ) && ERROR\_SUCCESS == reg.QueryBinaryValue(sValueName, arrByte.GetData(), &nLength)) { sData = CString((LPCTSTR)arrByte.GetData(), arrByte.GetSize()); }
the code is running on sData = ... nLength has 10 value, sData is empty, arrByte has 0 size ... what I am missing here ? Of course, in that registry location I have data ...
From CByteArray Class | Microsoft Docs[^]: "Before using an array, use SetSize to establish its size and allocate memory for it".
Mircea
-
From CByteArray Class | Microsoft Docs[^]: "Before using an array, use SetSize to establish its size and allocate memory for it".
Mircea
-
I have the following code:
CRegKey reg; CString sData; CByteArray arrByte; ULONG nLength = 0; if (ERROR\_SUCCESS == reg.Open(HKEY\_CURRENT\_USER, sKeyName, KEY\_READ) && ERROR\_SUCCESS == reg.QueryBinaryValue(sValueName, arrByte.GetData(), &nLength)) { sData = CString((LPCTSTR)arrByte.GetData(), arrByte.GetSize()); }
the code is running on sData = ... nLength has 10 value, sData is empty, arrByte has 0 size ... what I am missing here ? Of course, in that registry location I have data ...
_Flaviu wrote:
sData = CString((LPCTSTR)arrByte.GetData(), arrByte.GetSize());
Note that conversion from byte array to CString may give you an unexpected result in some cases, also when compiling as MBCS. For instance when the byte array contains one or more zero bytes. In such a case you will get a truncated string!