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. C / C++ / MFC
  4. QueryBinaryValue to CByteArray

QueryBinaryValue to CByteArray

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminhelpquestionlearning
4 Posts 3 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    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 ...

    Mircea NeacsuM V 2 Replies Last reply
    0
    • _ _Flaviu

      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 ...

      Mircea NeacsuM Offline
      Mircea NeacsuM Offline
      Mircea Neacsu
      wrote on last edited by
      #2

      From CByteArray Class | Microsoft Docs[^]: "Before using an array, use SetSize to establish its size and allocate memory for it".

      Mircea

      _ 1 Reply Last reply
      0
      • Mircea NeacsuM Mircea Neacsu

        From CByteArray Class | Microsoft Docs[^]: "Before using an array, use SetSize to establish its size and allocate memory for it".

        Mircea

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Thank you.

        1 Reply Last reply
        0
        • _ _Flaviu

          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 ...

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          _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!

          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