LONG RegSetValueEx(hkey, lpszValueName, dwReserved, fdwType, lpbData, cbData) | |||||
HKEY hkey; | /* identifies key to set value for | */ | |||
LPTSTR lpszValueName; | /* address of value to set | */ | |||
DWORD dwReserved; | /* must be zero | */ | |||
DWORD fdwType; | /* type of value | */ | |||
LPBYTE lpbData; | /* address of value data | */ | |||
DWORD cbData; | /* size of value data | */ |
The RegSetValueEx function stores data in the value field of an open configuration registry key, and can also set additional value and type information for the key.
hkey
Identifies a currently open key or any of the following predefined reserved handle values:
HKEY_CLASSES_ROOT HKEY_CURRENT_USER HKEY_LOCAL_MACHINE HKEY_USERS
lpszValueName
Points to a string that specifies the name of the value to set. If a value with this name is not present, the function adds it to the key. The string may contain up to MAX_PATH characters.
If lpszValue is NULL or points to an empty string, this function sets the value that would be set by the RegSetValue function.
dwReserved
Reserved; must be zero.
fdwType
Specifies the type of information to be stored in the key's value data. This parameter may have one of the following values:
Value | Meaning |
REG_BINARY | ||
Freeform binary data. | ||
REG_DWORD | ||
A 32-bit number. | ||
REG_DWORD_LITTLE_ENDIAN | ||
A 32-bit number in little endian format (same as REG_DWORD). | ||
REG_DWORD_BIG_ENDIAN | ||
A 32-bit number in big endian format | ||
REG_EXPAND_SZ | ||
A null-terminated Unicode string that contains unexpanded references to environment variables (PATH, for example). | ||
REG_LINK | ||
A Unicode symbolic link. | ||
REG_MULTI_SZ | ||
An array of null-terminated strings, terminated by two null characters. | ||
REG_NONE | ||
No defined value type. | ||
REG_RESOURCE_LIST | ||
A device-driver resource list. | ||
REG_SZ | ||
A null-terminated Unicode string. |
lpbData
Points to a buffer containing the data to be stored with this value name.
cbData
Specifies the length (in bytes) of the information to be stored in the key's value.
The return value is ERROR_SUCCESS if the function is successful. Otherwise, it is an error value.
Value lengths are limited by available memory. Long values (more than 2048 bytes) should be stored as files, with the filenames stored in the configuration registry. This will help the registry perform efficiently. Application elements such as icons, bitmaps, and executable files should be stored in the file system, not in the registry.
Use the RegFlushKey function to guarantee that the changes made by the RegSetValueEx function are saved.
The key specified by hkey must have been opened with KEY_SET_VALUE access. Use the RegCreateKeyEx or RegOpenKeyEx function to open the key.
If fdwType is REG_SZ, REG_MULTI_SZ, or REG_EXPAND_SZ and the ANSI version of this function is used (either by explicitly calling RegSetValueExA or by not defining UNICODE before including windows.h), lpbData must be an ANSI character string. The string is converted to Unicode before it is stored in the registry.
The RegSetValueEx function may be used as either a wide-character function (where text arguments must use Unicode) or an ANSI function (where text arguments must use characters from the Windows 3.x character set installed).
RegSetValue, RegQueryValue, RegQueryValueEx