INtime SDK Help
RtRegQueryValueEx
INtime SDK v6 > About INtime > INtime Kernel > Registry access > RtRegQueryValueEx

Retrieves the type and data for a specified value name associated with an open registry key.

The key identified by hKey must have been opened with KEY_QUERY_VALUE access. To open the key, use RtRegCreateKeyEx or RtRegOpenKeyEx.

If the value data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, and the ANSI version of this call is used (either by explicitly calling RtRegQueryValueEx or by not defining UNICODE before including the RTBASE.H file), this call converts the stored Unicode string to an ANSI string before copying it to the buffer pointed to by pData.

When calling RtRegQueryValueEx with hKey set to the HKEY_PERFORMANCE_DATA handle and a value string of a specified object, the returned data structure sometimes has unrequested objects. Don't be surprised; this is normal behavior. When calling RtRegQueryValueEx, you should always expect to walk the returned data structure to look for the requested object.

LONG RtRegQueryValueEx(
    HKEY hKey,           // handle to key to query
    LPTSTR lpValueName,  // address of name of value to query
    LPDWORD lpReserved,  // reserved
    LPDWORD lpType,      // address of buffer for value type
    LPBYTE lpData,       // address of data buffer
    LPDWORD lpcbData     // address of data buffer size
);

Parameters

hKey
Handle to a currently open key or any of the following predefined reserved handle values:

HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
HKEY_PERFORMANCE_DATA
lpValueName
Pointer to a null-terminated string that contains the name of the value to query.

If lpValueName is NULL or an empty string, "", the call retrieves the type and data for the key's unnamed or default value, if any.

Keys do not automatically have an unnamed or default value. Unnamed values can be of any type.
lpReserved
Reserved; must be NULL.
lpType
Pointer to a variable that receives the type of data associated with the specified value. The value returned through this parameter will be one of the following:
REG_BINARY Binary data in any form.
REG_DWORD A 32-bit number.
REG_DWORD_LITTLE_ENDIAN A 32-bit number in little-endian format. This is equivalent to REG_DWORD.
REG_DWORD_BIG_ENDIAN A 32-bit number in big-endian format.
REG_EXPAND_SZ A null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%"). It is either a Unicode or ANSI string depending on whether you use the Unicode or ANSI calls.
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 string. It is either a Unicode or ANSI string depending on whether you use the Unicode or ANSI calls.
The lpType parameter can be NULL if the type is not required.
lpData
Pointer to a buffer that receives the value's data. This parameter can be NULL if the data is not required.
lpcbData
Pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the lpData parameter. When the call returns, this variable contains the size of the data copied to lpData.

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, then lpcbData also includes the size of the terminating null character.

The lpcbData parameter can be NULL only if lpData is NULL.

If the buffer specified by lpData parameter is not large enough to hold the data, the call returns the value ERROR_MORE_DATA, and stores the required buffer size, in bytes, into the variable pointed to by lpcbData.

If lpData is NULL, and lpcbData is non-NULL, the call returns ERROR_SUCCESS, and stores the size of the data, in bytes, in the variable pointed to by lpcbData. This lets an application determine the best way to allocate a buffer for the value's data.

If hKey specifies HKEY_PERFORMANCE_DATA and the lpData buffer is too small, RtRegQueryValueEx returns ERROR_MORE_DATA but lpcbData does not return the required buffer size. This is because the size of the performance data can change from one call to the next. In this case, you must increase the buffer size and call RtRegQueryValueEx again passing the updated buffer size in the lpcbData parameter. Repeat this until the call succeeds. You need to maintain a separate variable to keep track of the buffer size, because the value returned by lpcbData is unpredictable.

Return Values

ERROR_SUCCESS
Success.
A nonzero status code defined in RTWIN32.H.
Failure.

Requirements

Versions Defined in Include Link to
INtime 3.0 intime/rt/include/rtbase.h rt.h rt.lib

See Also

Registry system calls, RtRegCreateKeyEx, RtRegOpenKeyEx, RtRegEnumKeyEx, RtRegEnumValue, RtRegQueryInfoKey