RegQueryValue
The RegQueryValue
function retrieves the value associated with the unnamed value for a specified
key in the registry. Values in the registry have name, type, and data
components. This function retrieves the data for a key s first value that has a
NULL name. This function is provided for compatibility with Windows version
3.1. Win32-based applications should use the RegQueryValueEx
LONG RegQueryValue(
HKEY hKey, |
// handle of key to
query |
LPCTSTR lpSubKey, |
// address of name
of subkey to query |
LPTSTR lpValue, |
// address of
buffer for returned string |
PLONG lpcbValue |
// address of
buffer for size of returned string |
); |
|
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
lpSubKey
Points to a
null-terminated string containing the name of the subkey of the hKey
parameter for which a value is to be retrieved. If this parameter is NULL or
points to an empty string, the function retrieves the value set by the RegSetValue
lpValue
Points to a
buffer that receives the value associated with the lpSubKey parameter.
The buffer should be big enough to contain the terminating null character. This
parameter can be NULL if the data is not required.
If lpValue
is NULL, and lpcbValue is not NULL, the function places the size in
bytes of the data referenced by the value key, including the terminating null
character, into the variable pointed to by lpcbValue. This lets an
application determine how to best preallocate a buffer for the value key s
data.
lpcbValue
Points to a
variable specifying the size, in bytes, of the buffer pointed to by the lpValue
parameter. When the function returns, this variable contains the size of the
data copied to lpValue, including the terminating null character.
If the buffer specified by lpValue parameter is not large enough
to hold the data, the function returns the value ERROR_MORE_DATA, and stores
the required buffer size, in bytes, into the variable pointed to by lpcbValue.
If lpValue is NULL, the function returns ERROR_SUCCESS, and
stores the size of the string, in bytes, into the variable pointed to by lpcbValue.
This lets an application determine the best way to allocate a buffer for the
value key s data.
In all cases the value returned in lpcbValue always includes the
size of the terminating null character in the string.
Return Values
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
Remarks
The key
identified by the hKey parameter must have been opened with
KEY_QUERY_VALUE access (KEY_READ access includes KEY_QUERY_VALUE access).
If the ANSI
version of this function is used (either by explicitly calling RegQueryValue
or by not defining Unicode before including the WINDOWS.H file), this function
converts the stored Unicode string to an ANSI string before copying it to the
buffer specified by the lpValue parameter.
See Also