Platform SDK: Registry |
The RegSetValue function sets the data for the default or unnamed value of a specified registry key. The data must be a text string.
Note This function is provided only for compatibility with 16-bit versions of Windows. Win32-based applications should use the RegSetValueEx function.
LONG RegSetValue( HKEY hKey, // handle to key LPCTSTR lpSubKey, // subkey name DWORD dwType, // information type LPCTSTR 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 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.
If the key specified by the lpSubKey parameter does not exist, the RegSetValue function creates it.
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.
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 the ANSI version of this function is used (either by explicitly calling RegSetValueA or by not defining UNICODE before including the Windows.h file), 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: No registry subkey or value name can exceed 255 characters.
Windows 95/98: The maximum size of a single registry value is 16,300 bytes. This limit includes the size of the data (cbData).
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, RegSetValueEx