RegQueryValueEx

  LONG RegQueryValueEx(hkey, lpszValueName, lpdwReserved, lpdwType, lpbData, lpcbData)    
  HKEY hkey; /* identifies key to set value for */
  LPTSTR lpszValueName; /* address of value buffer */
  LPDWORD lpdwReserved; /* reserved; should be NULL */
  LPDWORD lpdwType; /* address of type buffer */
  LPBYTE lpbData; /* address of data buffer */
  LPDWORD lpcbData; /* address of data buffer size */

The RegQueryValueEx function retrieves an open configuration registry key's type and value.

Parameters

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 buffer that receives the key's value name. This parameter must not be NULL.

lpdwReserved

Reserved; should be NULL.

lpdwType

Points to a variable that receives the key's value type code. The type code can be 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.

The lpdwType parameter may be NULL if the type is not required.

lpbData

Points to a buffer that receives the key's value data. This parameter may be NULL if the data is not required.

If lpdwType is REG_EXPAND_SZ, this function does not expand the environment-variable names in the value data. The ExpandEnvironmentStrings function can be used to expand the environment-variable names.

lpcbData

Points to a variable that specifies the size of the buffer at lpbData (in bytes). When the function returns, this variable contains the size of the data copied to lpbData. This parameter may be NULL only if lpbData is NULL.

Return Value

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

Comments

The key specified by hkey must have been opened with KEY_QUERY_VALUE access. Use the RegCreateKeyEx or RegOpenKeyEx function to open the key.

If the value data has type REG_SZ, REG_MULTI_SZ, or REG_EXPAND_SZ and the ANSI version of this function is used (either by explicitly calling RegQueryValueExA or by not defining UNICODE before including windows.h), this function converts the stored the stored Unicode string to an ANSI string before copying it to lpbData.

The RegQueryValueEx 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).

See Also

RegQueryValue, RegQueryInfoKey, RegEnumKey, RegEnumKeyEx, RegEnumValue