RegCreateKey

3.1

  #include <shellapi.h>    

  LONG RegCreateKey(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 RegCreateKey function creates the specified key. If the key already exists in the registration database, RegCreateKey opens it.

Parameters

hkey

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

lpszSubKey

Points to a null-terminated string specifying the subkey to open or create.

lphkResult

Points to the handle of the key that is opened or created.

Return Value

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

Comments

An application can create keys that are subordinate to the top level of the database by specifying HKEY_CLASSES_ROOT for the hKey parameter. An application can use the RegCreateKey function to create several keys at once. For example, an application could create a subkey four levels deep and the three preceding subkeys by specifying a string of the following form for the lpszSubKey parameter:

subkey1\subkey2\subkey3\subkey4

Example

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    */

See Also

RegCloseKey, RegOpenKey, RegSetValue