INtime SDK Help
RegQueryValueEx (iwin32)
INtime SDK v7.1 > About INtime > Alternate APIs > iwin32 API > iwin32 API > RegQueryValueEx (iwin32)

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

LONG RegQueryValueEx(
    HKEY hKey,
    LPTSTR lpValueName,
    LPDWORD lpReserved,
    LPDWORD lpType,
    LPBYTE lpData,
    LPDWORD lpcData


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


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.

Reserved; must be NULL.
Pointer to a variable that receives the type of data associated with the specified value. The value returned through this parameter is 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.

If the type is not required, the lpType parameter can be NULL.

Pointer to a buffer that receives the value's data. If the data is not required, this parameter can be NULL.
Pointer to a variable that specifies the number of bytes in 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 lpcData also includes the size of the terminating null character.

If lpData is NULL, the lpcData parameter can be 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 lpcData.

If lpData is NULL, and lpcData is non-NULL, the call returns ERROR_SUCCESS, and stores the size of the data, in bytes, in the variable pointed to by lpcData. An application can then 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, RegQueryValueEx returns ERROR_MORE_DATA but lpcData 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 RegQueryValueEx again passing the updated buffer size in the lpcData 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 lpcData is unpredictable.


The key identified by hKey must be opened with KEY_QUERY_VALUE access. To open the key, use RegCreateKeyEx or RegOpenKeyEx.

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 RegQueryValueEx or by not defining UNICODE before including the RTREG.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 RegQueryValueEx 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 RegQueryValueEx, you should always expect to walk the returned data structure to look for the requested object.

Return Values

A nonzero status code defined in RTWIN32.H.
Failure. For extended error information, see GetLastError


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


This function operates in the real-time portion of your application.

See Also

RegCreateKeyEx, RegEnumKeyEx, RegEnumValue, RegOpenKeyEx, RegQueryInfoKey, iwin32 API, iwin32 Overview