遍历注册表键名下的所有子键及所有子键数据
HKEY hKey_tmp = NULL;
HKEY hKey = NULL;
TCHAR comNum[20];
TCHAR comNumEx[20];
TCHAR achKey[60];
CString sActive;
DWORD i = 0;
DWORD cbMaxSubKey = 60; //
DWORD dwType = 20;//
DWORD dwSize = sizeof(comNum); //
DWORD retReg,retRegEx;
sActive =_T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\");
retReg=RegOpenKey(HKEY_LOCAL_MACHINE,sActive,&hKey);
if(retReg==ERROR_SUCCESS)
{
while (RegEnumKeyEx(hKey, i, achKey, &cbMaxSubKey, NULL, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS/*ERROR_SUCCESS*/)
{
if(RegOpenKey(HKEY_LOCAL_MACHINE, sActive+achKey, &hKey_tmp)==ERROR_SUCCESS)
{
retReg=RegQueryValueEx(hKey_tmp, _T("Display"), NULL, &dwType, (BYTE *)&comNumEx, &dwSize) ;
if(retReg==ERROR_SUCCESS)
{
CString str(comNumEx);
m_ComBox.AddString(str);
}
else
{
CString str;
str.Format(_T("%d"),GetLastError());
MessageBox(str);
}
}
else if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, sActive+achKey, 0,0, &hKey_tmp)==ERROR_SUCCESS)
{
retReg=RegQueryValueEx(hKey_tmp, _T("Display"), NULL, &dwType, (BYTE *)&comNumEx, &dwSize) ;
if(retReg==ERROR_SUCCESS)
{
CString str(comNumEx);
m_ComBox.AddString(str);
}
}
dwSize=20;
ZeroMemory(achKey,60);
cbMaxSubKey = 60;
i++;
}
有以下几个问题:1.为什么第二次执行RegQueryValueEx()返回就是0X000000EA值了。
2.RegOpenKey()与RegOpenKeyEx()有什么区别?
求大虾指点迷津。