网站首页  词典首页

请输入您要查询的函数:

 

术语 regqueryvalueex
释义 RegQueryValueEx
语法:
C++
LONG WINAPI RegQueryValueEx(
__in HKEY hKey,
__in_opt LPCTSTR lpValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_opt LPBYTE lpData,
__inout_opt LPDWORD lpcbData
);
RegQueryValueEx函数
检索类型和指定的值以开放的注册表项关联的名称的数据。
为了确保任何字符串值(REG_SZ,均为REG_MULTI_SZ,并REG_EXPAND_SZ的)返回的空终止,使用RegGetValue功能。
参数
hKey [in]
句柄到打开注册表项。密钥必须与已开放的KEY_QUERY_VALUE访问权限。有关更多信息,请参见注册表关键的安全和访问权限。
这种处理是由RegCreateKeyEx的,RegCreateKeyTransacted,RegOpenKeyEx,或RegOpenKeyTransacted函数返回。它也可以是下列预定义项之一:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_PERFORMANCE_DATA
HKEY_PERFORMANCE_NLSTEXT
HKEY_PERFORMANCE_TEXT
HKEY_USERS
lpValueName [中,可选]
该注册表值的名称。
如果lpValueName是NULL或空字符串,“”,检索功能和数据类型的主要的未命名或默认值,如果有的话。
如果lpValueName指定一个关键不是在注册表中,该函数返回ERROR_FILE_NOT_FOUND。
钥匙不会自动拥有一个未命名或默认值。未命名的值可以是任何类型。有关更多信息,请注册元素的大小限制。
lpReserved
这个参数是保留,必须为NULL。
lpType [指出,可选]
一项阿变量收到代码,以显示在指定的值存储的数据类型的指针。对于可能的类型代码清单,请参阅注册表值类型。该lpType参数可以是NULL类型代码是不需要的。
lpData [指出,可选]
阿一个缓冲区,它接收值的数据指针。此参数可以是NULL如果数据不需要。
lpcbData [中,指出,可选]
一个变量,它指定的缓冲区大小的指针指向的lpData参数,以字节为单位。当函数返回时,该变量包含了复制到lpData数据的大小。
该lpcbData参数可以是NULL,只有lpData为NULL。
如果数据是REG_SZ,均为REG_MULTI_SZ或REG_EXPAND_SZ类型,这样的规模包括任何终止空字符,或除非该数据没有他们储存字符。有关更多信息,请参见备注。
如果lpData参数所指定的缓冲区不够大,无法容纳数据,该函数返回ERROR_MORE_DATA并存储在变量所需的缓冲区大小指向lpcbData。在这种情况下,在lpData缓冲区的内容是不确定的。
如果lpData为NULL,lpcbData不为NULL,则函数返回ERROR_SUCCESS并存储数据的大小,以字节的变量,指向lpcbData。这使得一个应用程序,以确定最佳方式分配一个值的数据缓冲区。
如果hKey指定HKEY_PERFORMANCE_DATA和lpData缓冲区不够大,无法包含返回的数据,RegQueryValueEx返回ERROR_MORE_DATA并通过lpcbData参数返回的值是不确定的。这是因为性能数据的大小可以从一个电话改变未来。在这种情况下,您必须增加缓冲区的大小,并呼吁RegQueryValueEx再次通过在lpcbData参数更新的缓冲区大小。重复此,直到函数成功。您需要保持一个独立的变量来跟踪缓冲区的大小赛道,因为lpcbData返回的值是不可预测的。
如果lpValueName注册表值不存在,RegQueryValueEx返回ERROR_FILE_NOT_FOUND并通过lpcbData参数返回的值是不确定的。
返回值
如果函数成功,返回值是ERROR_SUCCESS。
如果函数失败,返回值是一个系统错误代码。
如果lpData缓冲区太小,无法接收数据,该函数返回ERROR_MORE_DATA。
如果lpValueName注册表值不存在,函数将返回ERROR_FILE_NOT_FOUND。
备注
应用程序通常要求RegEnumValue,以确定该值名称,然后RegQueryValueEx以检索数据的名称。
如果数据是REG_SZ,均为REG_MULTI_SZ或REG_EXPAND_SZ类型,字符串可能不会被存储在正确的终止空字符。因此,即使该函数返回ERROR_SUCCESS,应用程序应确保正确的字符串使用前终止,否则,就可能会覆盖缓冲区。 (请注意,均为REG_MULTI_SZ字符串应该有两终止空字符。)一种方法,应用程序可以确保正确终止字符串是使用RegGetValue,增加了终止如果需要空字符。
如果数据是REG_SZ,均为REG_MULTI_SZ或REG_EXPAND_SZ类型,此函数的使用ANSI版本(或者通过显式调用RegQueryValueExA或不明确之前,包括WINDOWS.H文件的UNICODE),这个函数转换成Unicode字符串存储到一个之前的ANSI复制到缓冲区字符串指向lpData。
当调用与hKey设置为HKEY_PERFORMANCE_DATA处理和一个指定对象的值字符串RegQueryValueEx函数,返回的数据结构有时未经请求的对象。不要惊讶,这是正常的行为。当调用RegQueryValueEx函数,您应该总是期望步行返回的数据结构,寻找所请求的对象。
请注意,操作访问某些注册表项被重定向。有关更多信息,请在注册处注册,虚拟化和32位和64位应用程序数据。
实例
确保您重新初始化值指出的lpcbData参数每次调用这个函数。这是非常重要的当您在一个循环调用这个函数,如下面的代码示例。
#include
#include
#include
#define TOTALBYTES 8192
#define BYTEINCREMENT 4096
void main()
{
DWORD BufferSize = TOTALBYTES;
DWORD cbData;
DWORD dwRet;
PPERF_DATA_BLOCK PerfData = (PPERF_DATA_BLOCK) malloc( BufferSize );
cbData = BufferSize;
printf("\\nRetrieving the data...");
dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
TEXT("Global"),
NULL,
NULL,
(LPBYTE) PerfData,
&cbData );
while( dwRet == ERROR_MORE_DATA )
{
// Get a buffer that is big enough.
BufferSize += BYTEINCREMENT;
PerfData = (PPERF_DATA_BLOCK) realloc( PerfData, BufferSize );
cbData = BufferSize;
printf(".");
dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
TEXT("Global"),
NULL,
NULL,
(LPBYTE) PerfData,
&cbData );
}
if( dwRet == ERROR_SUCCESS )
printf("\\n\\nFinal buffer size is %d\\n", BufferSize);
else printf("\\nRegQueryValueEx failed (%d)\\n", dwRet);
}

要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinreg.h(头文件:winuser.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode和ANSI namesRegQueryValueExW(Unicode)和RegQueryValueExA(ANSI)的
参见
ExpandEnvironmentStrings
RegCreateKeyEx的
RegEnumKeyEx
RegEnumValue
RegGetValue
登记职能
注册表概述
RegOpenKeyEx
RegQueryInfoKey
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==RegQueryValueEx Function
Retrieves the type and data for the specified value name associated with an open registry key.
To ensure that any string values (REG_SZ, REG_MULTI_SZ, and REG_EXPAND_SZ) returned are null-terminated, use the RegGetValue function.
Syntax
C++
LONG WINAPI RegQueryValueEx(
__in HKEY hKey,
__in_opt LPCTSTR lpValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_opt LPBYTE lpData,
__inout_opt LPDWORD lpcbData
);
Parameters
hKey [in]
A handle to an open registry key. The key must have been opened with the KEY_QUERY_VALUE access right. For more information, see Registry Key Security and Access Rights .
This handle is returned by the RegCreateKeyEx , RegCreateKeyTransacted , RegOpenKeyEx , or RegOpenKeyTransacted function. It can also be one of the following predefined keys :
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_PERFORMANCE_DATA
HKEY_PERFORMANCE_NLSTEXT
HKEY_PERFORMANCE_TEXT
HKEY_USERS
lpValueName [in, optional]
The name of the registry value.
If lpValueName is NULL or an empty string, "", the function retrieves the type and data for the key's unnamed or default value, if any.
If lpValueName specifies a key that is not in the registry, the function returns ERROR_FILE_NOT_FOUND.
Keys do not automatically have an unnamed or default value. Unnamed values can be of any type. For more information, see Registry Element Size Limits .
lpReserved
This parameter is reserved and must be NULL.
lpType [out, optional]
A 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 [out, optional]
A pointer to a buffer that receives the value's data. This parameter can be NULL if the data is not required.
lpcbData [in, out, optional]
A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.
The lpcbData parameter can be NULL only if lpData is NULL.
If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, this size includes any terminating null character or characters unless the data was stored without them. For more information, see Remarks.
If the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of the lpData buffer are 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 enables an application to determine the best way to allocate a buffer for the value's data.
If hKey specifies HKEY_PERFORMANCE_DATA and the lpData buffer is not large enough to contain all of the returned data, RegQueryValueEx returns ERROR_MORE_DATA and the value returned through the lpcbData parameter is undefined. 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.
If the lpValueName registry value does not exist, RegQueryValueEx returns ERROR_FILE_NOT_FOUND and the value returned through the lpcbData parameter is undefined.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a system error code .
If the lpData buffer is too small to receive the data, the function returns ERROR_MORE_DATA.
If the lpValueName registry value does not exist, the function returns ERROR_FILE_NOT_FOUND.
Remarks
An application typically calls RegEnumValue to determine the value names and then RegQueryValueEx to retrieve the data for the names.
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 terminating null characters. Therefore, even if the function returns ERROR_SUCCESS, the application should ensure that the string is properly terminated before using it; otherwise, it may overwrite a buffer. (Note that REG_MULTI_SZ strings should have two terminating null characters.) One way an application can ensure that the string is properly terminated is to use RegGetValue, which adds terminating null characters if needed.
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.
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 function, you should always expect to walk the returned data structure to look for the requested object.
Note that operations that access certain registry keys are redirected. For more information, see Registry Virtualization and 32-bit and 64-bit Application Data in the Registry .
Examples
Ensure that you reinitialize the value pointed to by the lpcbData parameter each time you call this function. This is very important when you call this function in a loop, as in the following code example.
#include
#include
#include
#define TOTALBYTES 8192
#define BYTEINCREMENT 4096
void main()
{
DWORD BufferSize = TOTALBYTES;
DWORD cbData;
DWORD dwRet;
PPERF_DATA_BLOCK PerfData = (PPERF_DATA_BLOCK) malloc( BufferSize );
cbData = BufferSize;
printf("\\nRetrieving the data...");
dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
TEXT("Global"),
NULL,
NULL,
(LPBYTE) PerfData,
&cbData );
while( dwRet == ERROR_MORE_DATA )
{
// Get a buffer that is big enough.
BufferSize += BYTEINCREMENT;
PerfData = (PPERF_DATA_BLOCK) realloc( PerfData, BufferSize );
cbData = BufferSize;
printf(".");
dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
TEXT("Global"),
NULL,
NULL,
(LPBYTE) PerfData,
&cbData );
}
if( dwRet == ERROR_SUCCESS )
printf("\\n\\nFinal buffer size is %d\\n", BufferSize);
else printf("\\nRegQueryValueEx failed (%d)\\n", dwRet);
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinreg.h (include Windows.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode and ANSI namesRegQueryValueExW (Unicode) and RegQueryValueExA (ANSI)
See Also
ExpandEnvironmentStrings
RegCreateKeyEx
RegEnumKeyEx
RegEnumValue
RegGetValue
Registry Functions
Registry Overview
RegOpenKeyEx
RegQueryInfoKey
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms724911(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:25:21