RegQueryValue

3.1

  #include <shellapi.h>    

  LONG RegQueryValue(hkey, lpszSubKey, lpszValue, lpcb)    
  HKEY hkey; /* handle of key to query */
  LPCSTR lpszSubKey; /* address of string for subkey to query */
  LPSTR lpszValue; /* address of buffer for returned string */
  LONG FAR* lpcb; /* address of buffer for size of returned string */

The RegQueryValue function retrieves the text string associated with a specified key.

Parameters

hkey

Identifies a currently open key (which can be HKEY_CLASSES_ROOT). This value should not be NULL.

lpszSubKey

Points to a null-terminated string specifying the name of the subkey of the hkey parameter for which a text string is retrieved. If this parameter is NULL or points to an empty string, the function retrieves the value of the hkey parameter.

lpszValue

Points to a buffer that contains the text string when the function returns.

lpcb

Points to a variable specifying the size, in bytes, of the buffer pointed to by the lpszValue parameter. When the function returns, this variable contains the size of the string copied to lpszValue, including the null-terminating character.

Return Value

The return value is ERROR_SUCCESS if the function is successful. Otherwise, it is an error value.

Example

The following example uses the RegOpenKey function to retrieve the handle of the StdFileEditing subkey, calls the RegQueryValue function to retrieve the name of an object handler and then calls the RegDeleteKey function to delete the key if its value is nwappobj.dll:

char szBuff[80];
LONG cb;
HKEY hkStdFileEditing;

if (RegOpenKey(HKEY_CLASSES_ROOT,
        "NewAppDocument\\protocol\\StdFileEditing",
        &hkStdFileEditing) == ERROR_SUCCESS) {

    cb = sizeof(szBuff);
    


if (RegQueryValue(hkStdFileEditing,
            "handler",
            szBuff,
            &cb) == ERROR_SUCCESS
            && lstrcmpi("nwappobj.dll", szBuff) == 0)
        RegDeleteKey(hkStdFileEditing, "handler");
    RegCloseKey(hkStdFileEditing);
}

See Also

RegEnumKey