MSDN Documentation > Windows > API Reference > Winreg > Registry Functions > RegCreateKeyEx

RegCreateKeyEx Function

Syntax

LONG RegCreateKeyEx(
                  HKEY          hKey,
                  LPCTSTR       lpSubKey,
                  DWORD         Reserved,
                  LPTSTR        lpClass,
                  DWORD         dwOptions,
                  REGSAM        samDesired,
                  CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
                  PHKEY         phkResult,
                  LPDWORD       lpdwDisposition
                );

Parameters

Return Value

If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero return code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Remarks

The RegCreateKeyEx function creates a new key or opens an existing key. If the key is created, its default value is set to an empty string. If the key already exists, the function opens it and retrieves its information. If the key does not exist, it is created with the specified security attributes and options.

If lpClass is NULL, the key will have no class. If lpSecurityAttributes is NULL, the key will have a default security descriptor.

The access rights specified by samDesired are checked against the security descriptor of the key. If the calling process does not have the requested access rights, the function fails and returns ERROR_ACCESS_DENIED.

It is important to close the handle returned in phkResult when it is no longer needed by calling RegCloseKey.

Requirements

   
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header Winreg.h (include Windows.h)
Library Advapi32.lib
DLL Advapi32.dll

See Also