RegQueryValue function

zhaozj2021-02-11  181

RegQueryValueex (e)

The RegqueryValueex Function Retrieves The Type and Data for a Specified Value Name Associated with an Open Registry Key.

The function regQueryValueex retrieves an open registry key value associated with a given variable data or variable.

Long RegQueryValueex (

HKEY HKEY, / / ​​HANDLE TO Key Primary key handle

LPCTSTR LPVALUENAME, / / ​​VALUE NAME sub-key name

LPDWORD LPRESERVED, // Reserved

LPDWORD LPTYPE, / / ​​TYPE BUFFER

LPBYTE LPDATA, / / ​​DATA BUFFER Stores the buffer of the return value

LPDWORD LPCBDATA / / SIZE OF DATA BUFFER Stores the size of the buffer that returns the value

);

Parameters

HKEY

[in] Handle to a currently open key or one of the folowing predefined keys:

HKEY_CLASSES_ROOT

HKEY_CURRENT_CONFIG

HKEY_CURRENT_USER

HKEY_LOCAL_MACHINE

HKEY_USERS

Windows NT / 2000 / XP: HKEY_PERFORMANCE_DATA

Windows XP: HKEY_PERFORMANCE_TEXT

Windows XP: HKEY_PERFORMANCE_NLSText

Windows 95/98 / Me: HKEY_DYN_DATA

LPVALUENAME

Pointer to a null-terminated string containing the name of the value to query.

IF LPVALUENAME INY.

Windows 95/98 / Me:.. Every key has a default value that initially does not contain data On Windows 95, the default value type is always REG_SZ On Windows 98, the type of a key's default value is initially REG_SZ, but RegSetValueEx can Specify a Default Value with a Different Type.

Windows NT / 2000 / XP: Keys Do Not Automatically Have An Unnamed or Default Value. Unnamed Values ​​Can Be of any type.

LPRESERVED

RESERVED; Must Be NULL.

LPTYPE

[Out] Pointer to a variable that receives a code indicating the type of data stored in the specified value. For a list of the possible type codes, see Registry Value Types. The lpType parameter can be NULL if the type code is not required. LPDATA

...........................

LPCBDATA

.

IF The Data Has The REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ TYPE, THEN LPCBDATA WILL ALSO include The size of the terminating null character or 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 function returns the value ERROR_MORE_DATA, and stores the required buffer size, in bytes, into the variable pointed to by lpcbData. In this case, the contents of the lpValue Buffer is undefined.

If lpData is NULL, and lpcbData is non-NULL, the function 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.

Window NT: If hKey specifies HKEY_PERFORMANCE_DATA and the lpData buffer is too small, RegQueryValueEx 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 RegQueryValueEx again passing the updated buffer size in the lpcbData parameter. Repeat this until the function succeeds. you need to maintain a separate variable to keep track of the buffer size, because the value returned by lpcbData is unpredictable 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 formatage function with the format_message_from_system flag to get a generic description of the error.

Remarks

THE Key Identified by HKEY MUST HAVE BEEN OPENED WIY_QUERY_VALUE Access. To Open the key, use the regreatekeyex or regopenkeyex function.

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with the proper null-terminating characters. Applications should ensure that the string is properly terminated before using it, otherwise, the application may fail by overwriting a buffer .

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, and the ANSI version of this function is used (either by explicitly calling RegQueryValueExA 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 pointed to by lpdata.

Window NT / 2000: When calling the RegQueryValueEx function 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 Do not be surprised; this is normal behavior When calling the RegQueryValueEx.. .

Windows 95/98 / Me: RegQueryValueExW is supported by the Microsoft Layer for Unicode To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98 / Me Systems..

Example Code

For An Example, See Retrieving Data from The Registry.

Requirements

Windows NT / 2000 / XP: INCLUDED IN WINDOWS NT 3.1 AND LATER.

Windows 95/98 / Me: Included in Windows 95 and later.

Header: declared in winreg.h; incrude windows.h.

Library: USE Advapi32.lib.

Unicode: Implement AS Unicode and ANSI Versions on Windows NT / 2000 / XP. Also Supported by Microsoft Layer for Unicode.

RegQueryValueex (C)

The function regQueryValueex retrieves an open registry key value associated with a given variable data or variable.

Long RegQueryValueex (

HKEY HKEY, / / ​​Probe Handle

LPCTSTR LPVALUENAME, // Sub key name

LPDWORD LPRESERVED, / /

LPDWORD LPTYPE, / / ​​TYPE BUFFER

LPBYTE LPDATA, // Store buffers of the return value

LPDWORD LPCBDATA

File: // Store the size of the buffer of the return value

);

parameter:

HKEY points to a handle that has been opened or one of the following values

HKEY_CLASSES_ROOT

HKEY_CURRENT_CONFIG

HKEY_CURRENT_USER

HKEY_LOCAL_MACHINE

HKEY_USERS

Windows NT / 2000 / XP: HKEY_PERFORMANCE_DATA

Windows XP: HKEY_PERFORMANCE_TEXT

Windows XP: HKEY_PERFORMANCE_NLSText

Windows 95/98 / Me: HKEY_DYN_DATA

LPVALUENAME

Pointing a string ending with empty characters, which contains the value name to query.

If LPVALUENAME is NULL or an empty string, the function will retrieve the unnamed or default value of this specified key value. Windows NT / 2000 / XP: Keys Do Not Automatically Have An Unnamed or Default Value. Unnamed Values ​​Can Be of any type.

Windows 95/98 / ME: Any key has a numeric type that does not contain data default. In Window95, the default value type is always reg_sz. In Windows 98, the default data type of the key is initialized to REG_SZ, but the function RegSetValueEx can specify a different data type as the default data type.

Windows NT / 2000 / XP: The key cannot be automatically named or default data types. For clear values ​​can be any type of data type

LPRESERVED

Reserved parameters must be NULL

LPTYPE

[Output] Points to receive variables of the data type of the store specific data, and the list of registered variables can be viewed for a list of specific types. If this type is not a must, the parameter lptype can be NULL.

LPDATA

Point a buffer that receives the data value, if this data is not a must-have parameter, it can be NULL.

LPCBDATA

[Input / Output] points to a variable, which indicates the size of the buffer to use byte by the parameter LPDATA. This variable contains the size of the content in LPDATA when the function returns.

If the data type is REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ, the size of the parameter LPCBDATA will contain end empty characters or empty strings.

If the parameter LPDATA is null, the parameter LPCBDATA will also be empty.

If the buffer pointed to by the parameter LPDATA is too small without storing all the returned data, the function will return error code error_more_data, the parameter LPCBData will store the actual size required by the buffer, the buffer, in this case LPValue The pointer points to the buffer will not be defined.

If lpdata is null, and LPCBData is not null, the function returns an error code error_suCcess, and saves the size of the data to be saved with byte calculation. This will be the best way to determine allocation data buffers.

Window NT: If the key value handle HKEY points to HKEY_PERFORMANCE_DATA and the buffer LPDATA pointed to by LPDATA is too small, the function regQueryValueex will return error code error_more_data, and the parameter LPCBDATA will not return the required buffer size. This is because the size of the run data can be changed as different calls. In this case, you must increase the buffer and reuse the function regQueryValueex, calibrate the parameter lpcbdata size, and repeat such actions until the function runs successfully. Because the value returned by lpcbdata cannot be known as a small, you need a separate variable to guide the size of the buffer.

return value

If the function runs success, return paper will be Error_Success. If the function runs, the return value is an error code defined in the header file WineError.h is not zero. You can get a general error description by the function formatMessage to mark format_message_from_system.

Note

The key value of the flag parameter HKEY is turned on. You must have the right key_query_value. Open a key to view the function RegcreateKeyex and RegopenKeyex.

If the data type is REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ, the string may not be ended with empty characters. The application needs to make sure the string is complete when applying it. Otherwise, the application may overwrite the buffer and run failure.

If the data type is REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ, and the function is an ANSI version (or a clear call function regQueryvalueexa or no unicode "before defining the header file Windows.h, the function will be saved before copying to the buffer pointed to the LPDATA. The Unicode string turns into an ANSI string.

WINDOW NT / 2000: When HKEY is set to the HKEY_PERFORMANCE_DATA and a variable string, the function regQueryValueex is called when a variable string is pointing to a specific object, and the returned structure is sometimes the object that is not requested, in fact, this is normal. When the function RegQueryValueex is called, you always expect the data structure that returns to be the object you need. (You Should Always Expect to Walk the Returned Data Structure to Look for the Requested Object.)

Windows 95/98 / ME: No registered subkey or data values ​​may exceed 255 characters.

Windows 95/98 / ME: Microsoft functions RegQueryValueexw support Unicode. To use this function, you must add specific file support for your application. View Microsoft's Unicode On Windows 95/98 / ME Systems.

Example code:

See Retrieving Data from The Registry.

demand

Windows NT / 2000 / XP: Support in Windows NT 3.1 or later.

Windows 95/98 / ME: Supports Windows 95 and its later versions.

Header: Declaring in file WinReg.h; definition in Windows.h in header file

Library: With Advapi32.lib.

Unicode: Execute View Unicode and ANSI Versions On Windows NT / 2000 / XP can also view support for Microsoft Layer For Unicode.

转载请注明原文地址:https://www.9cbs.com/read-5687.html

New Post(0)