RegOpenKey

3.1

  #include <shellapi.h>    

  LONG RegOpenKey(hkey, lpszSubKey, lphkResult)    
  HKEY hkey; /* handle of an open key */
  LPCSTR lpszSubKey; /* address of string for subkey to open */
  HKEY FAR* lphkResult; /* address of handle of open key */

The RegOpenKey function opens the specified key.

Parameters

hkey

Identifies an open key (which can be HKEY_CLASSES_ROOT). The key opened by the RegOpenKey function is a subkey of the key identified by this parameter. This value should not be NULL.

lpszSubKey

Points to a null-terminated string specifying the name of the subkey to open.

lphkResult

Points to the handle of the key that is opened.

Return Value

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

Comments

Unlike the RegCreateKey function, the RegOpenKey function does not create the specified key if the key does not exist in the database.

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

RegCreateKey