BOOL RegQueryKeyValue( HKEY hKey, TCHAR *lpName, TCHAR *name, TCHAR *value )
{
HKEY handle;
if ( ERROR_SUCCESS != RegOpenKeyEx( hKey, lpName, NULL, KEY_ALL_ACCESS, &handle ) )
{
return FALSE;
}
TCHAR achkey[MAX_KEY_LENGTH];
DWORD cbname;
TCHAR achclass[MAX_PATH];
DWORD cchclassname = MAX_PATH;
DWORD csubkeys = 0;
DWORD cbmaxsubkey;
DWORD cchmaxclass;
DWORD cvalues;
DWORD cchmaxvalue;
DWORD cbmaxvaluedata;
DWORD cbsecuritydescriptor;
FILETIME ftlastwritetime;
DWORD retCode;
retCode = RegQueryInfoKey(
handle,
achclass,
&cchclassname,
NULL,
&csubkeys,
&cbmaxsubkey,
&cchmaxclass,
&cvalues,
&cchmaxvalue,
&cbmaxvaluedata,
&cbsecuritydescriptor,
&ftlastwritetime);
bool bfind = false;
TCHAR pName[MAX_KEY_LENGTH];
BYTE pValue[MAX_VALUE_NAME];
for( int i=0; i<cvalues; i++ )
{
memset( pName, 0, MAX_KEY_LENGTH );
memset( pValue, 0, MAX_VALUE_NAME );
DWORD nameSize = MAX_KEY_LENGTH-1;
DWORD valueSize = MAX_VALUE_NAME-1;
retCode = RegEnumValue(
handle,
i,
pName,
&nameSize,
NULL,
NULL,//类型
pValue,
&valueSize);
if( ERROR_SUCCESS != retCode )
{
return FALSE;
}
}
}
出现此错误的原因是指定的字符串大小不足以容纳查询到的枚举到的键值, 每次重新指定字符串的大小即可
可参考:http://www.cnblogs.com/shipfi/archive/2006/05/18/403619.html