An application can use the RegCreateKey and RegSetValue functions to add keys to the registration database and the RegCloseKey function to indicate that a key is no longer needed by the application. Other registration functions allow an application to query the contents of the database and delete keys.
An application can use the RegEnumKey function to determine the subkeys of a specified key. Because the first parameter of RegEnumKey must be the handle of an open key, this function is typically preceded by a call to the RegOpenKey function and followed by a call to RegCloseKey. (Because the HKEY_CLASSES_ROOT key is always open, bracketing RegEnumKey with RegOpenKey and RegCloseKey is not strictly necessary when HKEY_CLASSES_ROOT is specified as the first parameter of RegEnum-Key. Using RegOpenKey and RegCloseKey is a time optimization in this case, however.) The RegQueryValue function retrieves the text string that has been associated with a key name.
The following example uses the RegEnumKey function to put the values associated with top-level keys into a list box:
HKEY hkRoot;
char szBuff[80], szValue[80];
static DWORD dwIndex;
LONG cb;
if (RegOpenKey(HKEY_CLASSES_ROOT, NULL, &hkRoot) == ERROR_SUCCESS) {
for (dwIndex = 0; RegEnumKey(hkRoot, dwIndex, szBuff,
sizeof(szBuff)) == ERROR_SUCCESS; ++dwIndex) {
if (*szBuff == '.')
continue;
cb = sizeof(szValue);
if (RegQueryValue(hkRoot, (LPSTR) szBuff, szValue,
&cb) == ERROR_SUCCESS)
SendDlgItemMessage(hDlg, ID_ENUMLIST, LB_ADDSTRING, 0,
(LONG) (LPSTR) szValue);
}
RegCloseKey(hkRoot);
}
The following example uses 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);
}