Get exact subKey value from registry

This is a discussion on Get exact subKey value from registry within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm using RegQueryValueEx to read a REG_SZ type of a subKey value from registry. The value found with regedit ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    58

    Get exact subKey value from registry

    Hi,
    I'm using RegQueryValueEx to read a REG_SZ type of a subKey value from registry. The value found with regedit is 6.1.6002, however I get back just 6002 as value for installedVer.
    The code (return value is ERROR_SUCCESS) is
    Code:
    TCHAR installedVer[20] = { 0 };
    DWORD DataType = REG_SZ;
    DWORD BufferLength = wcslen(installedVer);
    HKEY hKey;
    RegQueryValueEx(hKey, L"CurrentBuild", 0, &DataType, (BYTE *)installedVer, &BufferLength);
    Any idea why?
    Thanks

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Because wcslen() is the number of characters currently in the string, not the size of the char buffer?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    58
    Thanks novacain. The BufferLength needs just to be large enough, and I've done that shortcut which, I agree, could have been a cause for failure, but not here.
    The code is ok as it is, the reason of the bug was just the fact I called other code than this in another application module.
    Stupid me!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Registry, Regedit
    By franse in forum C++ Programming
    Replies: 21
    Last Post: 01-29-2009, 09:57 AM
  2. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  3. Registry
    By gvector1 in forum C# Programming
    Replies: 0
    Last Post: 07-30-2003, 05:02 PM
  4. LOGFONT struct & Registry :: MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 05-27-2002, 04:38 PM
  5. Registry Access
    By ExDigit in forum Windows Programming
    Replies: 3
    Last Post: 01-04-2002, 04:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21