#include <shellapi.h> |
LONG RegCloseKey(hkey) | |||||
HKEY hkey; | /* handle of key to close | */ |
The RegCloseKey function closes a key. Closing a key releases the key's handle. When all keys are closed, the registration database is updated.
hkey
Identifies the open key to close.
The return value is ERROR_SUCCESS if the function is successful. Otherwise, it is an error value.
The RegCloseKey function should be called only if a key has been opened by either the RegOpenKey function or the RegCreateKey function. The handle for a given key should not be used after it has been closed, because it may no longer be valid. Key handles should not be left open any longer than necessary.
The following example uses the RegCreateKey function to create the handle of a protocol, uses the RegSetValue function to set up the subkeys of the protocol, and then calls RegCloseKey to save the information in the database:
HKEY hkProtocol;
if (RegCreateKey(HKEY_CLASSES_ROOT, /* root */
"NewAppDocument\\protocol\\StdFileEditing", /* protocol string */
&hkProtocol) != ERROR_SUCCESS) /* protocol key handle */
return FALSE;
RegSetValue(hkProtocol, /* handle of protocol key */
"server", /* name of subkey */
REG_SZ, /* required */
"newapp.exe", /* command to activate server */
10); /* text string size */
RegSetValue(hkProtocol, /* handle of protocol key */
"verb\\0", /* name of subkey */
REG_SZ, /* required */
"EDIT", /* server should edit object */
4); /* text string size */
RegCloseKey(hkProtocol); /* closes protocol key and subkeys */