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. Buffer data size

Buffer data size

Scheduled Pinned Locked Moved C / C++ / MFC
question
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

    Hi all. I have a doubt: how ulSize data buffer size should be:

    CString sValue;
    ULONG ulSize = \_MAX\_PATH;
    lRet = RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE\*)sValue.GetBuffer(\_MAX\_PATH), &ulSize);
    sValue.ReleaseBuffer();
    

    or

    CString sValue;
    ULONG ulSize = \_MAX\_PATH \* sizeof(TCHAR);
    lRet = RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE\*)sValue.GetBuffer(\_MAX\_PATH), &ulSize);
    sValue.ReleaseBuffer();
    

    I guess that ulSize should be _MAX_PATH * sizeof(TCHAR); like in the second code ... but I am not sure ... can you tell me how is right ? Thank you.

    J L 2 Replies Last reply
    0
    • _ _Flaviu

      Hi all. I have a doubt: how ulSize data buffer size should be:

      CString sValue;
      ULONG ulSize = \_MAX\_PATH;
      lRet = RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE\*)sValue.GetBuffer(\_MAX\_PATH), &ulSize);
      sValue.ReleaseBuffer();
      

      or

      CString sValue;
      ULONG ulSize = \_MAX\_PATH \* sizeof(TCHAR);
      lRet = RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE\*)sValue.GetBuffer(\_MAX\_PATH), &ulSize);
      sValue.ReleaseBuffer();
      

      I guess that ulSize should be _MAX_PATH * sizeof(TCHAR); like in the second code ... but I am not sure ... can you tell me how is right ? Thank you.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      From MSDN RegQueryValueEx function[^]:

      Quote:

      lpcbData [in, out, optional] A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes.

      So it must be the second version.

      _ 1 Reply Last reply
      0
      • _ _Flaviu

        Hi all. I have a doubt: how ulSize data buffer size should be:

        CString sValue;
        ULONG ulSize = \_MAX\_PATH;
        lRet = RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE\*)sValue.GetBuffer(\_MAX\_PATH), &ulSize);
        sValue.ReleaseBuffer();
        

        or

        CString sValue;
        ULONG ulSize = \_MAX\_PATH \* sizeof(TCHAR);
        lRet = RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE\*)sValue.GetBuffer(\_MAX\_PATH), &ulSize);
        sValue.ReleaseBuffer();
        

        I guess that ulSize should be _MAX_PATH * sizeof(TCHAR); like in the second code ... but I am not sure ... can you tell me how is right ? Thank you.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Version 1, as CString adjusts itself to the character type in use. See https://msdn.microsoft.com/en-us/library/aa314880%28v=vs.60%29.aspx[^]. A simple test wolud confirm it for you.

        1 Reply Last reply
        0
        • J Jochen Arndt

          From MSDN RegQueryValueEx function[^]:

          Quote:

          lpcbData [in, out, optional] A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes.

          So it must be the second version.

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

          Thank you !

          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