void CRegExplorerView::EnumerateValues(HKEY hKey, LPCTSTR cstrKey)
{
static HKEY hLastKey = hKey;
LONG lResult;
DWORD dwIndex = 0;
HKEY hCurKey = hKey;
DWORD dwKeyType;
DWORD dwKeyDataLength, dwKeyNameLen;
LPBYTE pbbinKeyData = NULL;
TCHAR *tcKeyName = NULL;
TCHAR tcDataType[1024] = _T( " ");
lResult = RegOpenKeyEx(hCurKey, cstrKey, 0, KEY_QUERY_VALUE , &hKey);
if(lResult != ERROR_SUCCESS)
return;
DWORD lNoOfValues = 0;
DWORD lLongestKeyNameLen = 1;
DWORD lLongestDataLen = 1;
lResult = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &lNoOfValues, &lLongestKeyNameLen, &lLongestDataLen,NULL, NULL);
if(lResult != ERROR_SUCCESS)
return;
hLastKey = hKey;
lLongestKeyNameLen++;
lLongestDataLen++;
tcKeyName = new TCHAR[lLongestKeyNameLen];
pbbinKeyData = new BYTE[lLongestDataLen];
CString cstrFinalData, cstrTemp;
while(TRUE)
{
memset(pbbinKeyData, 0, lLongestDataLen);
memset(tcKeyName, 0, lLongestKeyNameLen);
dwKeyType = dwKeyDataLength = dwKeyNameLen = 0;
dwKeyNameLen = lLongestKeyNameLen;
dwKeyDataLength = lLongestDataLen;
lResult = RegEnumValue(hKey, dwIndex, tcKeyName, &dwKeyNameLen, NULL, &dwKeyType, pbbinKeyData, &dwKeyDataLength);
if(lResult == ERROR_NO_MORE_ITEMS)
break;
AddRegistryItem(tcKeyName, dwKeyType, pbbinKeyData, dwKeyDataLength, dwIndex);//显示数据于ListView
dwIndex++;
}
RegCloseKey(hKey);
delete tcKeyName;
delete pbbinKeyData;
}