Platform SDK: Registry |
The RegSetValueEx function sets the data and type of a specified value under a registry key.
LONG RegSetValueEx( HKEY hKey, // handle to key LPCTSTR lpValueName, // value name DWORD Reserved, // reserved DWORD dwType, // value type CONST BYTE *lpData, // value data DWORD cbData // size of value data );
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
Windows NT/2000: HKEY_PERFORMANCE_DATA
Windows 95/98: HKEY_DYN_DATA
If lpValueName is NULL or an empty string, "", the function sets the type and data for the key's unnamed or default value.
Windows 95/98: On Windows 95, the type of a key's default value is always REG_SZ, so the dwType parameter must specify REG_SZ for an unnamed value. On Windows 98, an unnamed value can be of any type.
Windows NT/2000: Registry keys do not have default values, but they can have one unnamed value, which can be of any type.
Windows 95: For string-based data types, such as REG_SZ, RegSetValueEx appends a NULL to the end of the value string.
Windows NT: For string-based data types, RegSetValueEx does not append a NULL to the end of the value string.
Windows 95: The size includes the size of the NULL added to the end of the string passed in the lpData parameter.
Windows NT: The size is the exact size of the string passed in the lpData parameter.
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error 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.
Value lengths are limited by available memory. Long values (more than 2048 bytes) should be stored as files with the filenames stored in the registry. This helps the registry perform efficiently. Application elements such as icons, bitmaps, and executable files should be stored as files and not be placed in the registry.
The key identified by the hKey parameter must have been opened with KEY_SET_VALUE access. To open the key, use the RegCreateKeyEx or RegOpenKeyEx function.
If dwType is the REG_SZ, REG_MULTI_SZ, or REG_EXPAND_SZ type and the ANSI version of this function is used (either by explicitly calling RegSetValueExA or by not defining UNICODE before including the Windows.h file), the data pointed to by the lpData parameter must be an ANSI character string. The string is converted to Unicode before it is stored in the registry.
Windows 95/98: The maximum size of a single registry value is 16,300 bytes. This limit includes the size of the data (cbData) and the size of the value name (lpValueName).
Windows 95/98: There is a 64K limit for the total size of all values of a key.
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winreg.h; include Windows.h.
Library: Use Advapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.
Registry Overview, Registry Functions, RegCreateKeyEx, RegFlushKey, RegOpenKeyEx, RegQueryValue, RegQueryValueEx, RegSetValue