C++ - getting null values in value read from registry

后端 未结 2 1376
名媛妹妹
名媛妹妹 2021-01-27 00:50

My application properly reads and writes to the registry. Now, I need to read a registry value from:

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography\\Machi         


        
相关标签:
2条回答
  • 2021-01-27 01:05

    You have built targeting Unicode and so the registry API is returning UTF-16 Unicode text. Instead of char use wchar_t and remember that each wchar_t element is 2 bytes wide.

    Do also make sure that you account for the returned string not being null-terminated, as described in the documentation. You must take account of the value returned in dwBufSize.

    0 讨论(0)
  • 2021-01-27 01:20

    I get the guid but in value array after each character their is a "\0" value due to which only first character of array gets assigned to string. This is wierd!

    This is because you are calling the Unicode version of RegQueryValueEx(), so the string is returned in Unicode (UTF-16).

    You will have to use wide character parameters to get the value.

    Change this line:

    char value[256] = "\0";
    

    To use wchar_t instead.

    0 讨论(0)
提交回复
热议问题