a prob with HKEY
-
BOOL checkExistence(HKEY *hKey, LPCTSTR lpszAppName)
{
CRegKey regKey;if( regKey.Open(HKEY\_LOCAL\_MACHINE, \_T("SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall"), KEY\_READ) != ERROR\_SUCCESS ) return FALSE; DWORD dwIndex = 0; DWORD cbName = 128; TCHAR szSubkeyName\[128\]; CString strSubkeyName; int nHasAllItems = 0; while( regKey.EnumKey(dwIndex, szSubkeyName, &cbName) != ERROR\_NO\_MORE\_ITEMS ) { dwIndex++; cbName = 128; // TCHAR->CString strSubkeyName.Format(\_T("%s"), szSubkeyName); if( strSubkeyName.Compare(lpszAppName) ) { nHasAllItems++; continue; } else break; } regKey.Close(); if( nHasAllItems == dwIndex ) return FALSE; else { \*hKey = regKey.m\_hKey;// this causes debug assertion failure:m\_hKey!=0 return TRUE; }
}
I wrote this funx to check whether there's a particular installed app in the registry. After calling this funx, hKey is expected to be assigned the registry handle. But prob occurs as Ive indicated above.
-
BOOL checkExistence(HKEY *hKey, LPCTSTR lpszAppName)
{
CRegKey regKey;if( regKey.Open(HKEY\_LOCAL\_MACHINE, \_T("SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall"), KEY\_READ) != ERROR\_SUCCESS ) return FALSE; DWORD dwIndex = 0; DWORD cbName = 128; TCHAR szSubkeyName\[128\]; CString strSubkeyName; int nHasAllItems = 0; while( regKey.EnumKey(dwIndex, szSubkeyName, &cbName) != ERROR\_NO\_MORE\_ITEMS ) { dwIndex++; cbName = 128; // TCHAR->CString strSubkeyName.Format(\_T("%s"), szSubkeyName); if( strSubkeyName.Compare(lpszAppName) ) { nHasAllItems++; continue; } else break; } regKey.Close(); if( nHasAllItems == dwIndex ) return FALSE; else { \*hKey = regKey.m\_hKey;// this causes debug assertion failure:m\_hKey!=0 return TRUE; }
}
I wrote this funx to check whether there's a particular installed app in the registry. After calling this funx, hKey is expected to be assigned the registry handle. But prob occurs as Ive indicated above.
How are you calling
checkExistence()
?Krauze wrote:
strSubkeyName.Format(_T("%s"), szSubkeyName);
What's wrong with: strSubkeyName = szSubkeyName;
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
How are you calling
checkExistence()
?Krauze wrote:
strSubkeyName.Format(_T("%s"), szSubkeyName);
What's wrong with: strSubkeyName = szSubkeyName;
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
BOOL checkExistence(HKEY *hKey, LPCTSTR lpszAppName)
{
CRegKey regKey;if( regKey.Open(HKEY\_LOCAL\_MACHINE, \_T("SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall"), KEY\_READ) != ERROR\_SUCCESS ) return FALSE; DWORD dwIndex = 0; DWORD cbName = 128; TCHAR szSubkeyName\[128\]; CString strSubkeyName; int nHasAllItems = 0; while( regKey.EnumKey(dwIndex, szSubkeyName, &cbName) != ERROR\_NO\_MORE\_ITEMS ) { dwIndex++; cbName = 128; // TCHAR->CString strSubkeyName.Format(\_T("%s"), szSubkeyName); if( strSubkeyName.Compare(lpszAppName) ) { nHasAllItems++; continue; } else break; } regKey.Close(); if( nHasAllItems == dwIndex ) return FALSE; else { \*hKey = regKey.m\_hKey;// this causes debug assertion failure:m\_hKey!=0 return TRUE; }
}
I wrote this funx to check whether there's a particular installed app in the registry. After calling this funx, hKey is expected to be assigned the registry handle. But prob occurs as Ive indicated above.
"hKey is expected to be assigned the registry handle." but how as you did regKey.Close(); before *hKey = regKey.m_hKey; ?? Try
*hKey = regKey.Detach();
Remeber to call RegCloseKey() on the obtained handle once finished using it.
modified on Wednesday, July 28, 2010 1:30 AM
-
How are you calling
checkExistence()
? Aso, have you considered something a little more manageable, like:BOOL checkExistence( HKEY *hKey, LPCTSTR lpszAppName )
{
CString strKey;
strKey.Format(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s"), lpszAppName);return RegOpenKey(HKEY\_LOCAL\_MACHINE, strKey, hKey) == ERROR\_SUCCESS;
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
BOOL checkExistence(HKEY *hKey, LPCTSTR lpszAppName)
{
CRegKey regKey;if( regKey.Open(HKEY\_LOCAL\_MACHINE, \_T("SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall"), KEY\_READ) != ERROR\_SUCCESS ) return FALSE; DWORD dwIndex = 0; DWORD cbName = 128; TCHAR szSubkeyName\[128\]; CString strSubkeyName; int nHasAllItems = 0; while( regKey.EnumKey(dwIndex, szSubkeyName, &cbName) != ERROR\_NO\_MORE\_ITEMS ) { dwIndex++; cbName = 128; // TCHAR->CString strSubkeyName.Format(\_T("%s"), szSubkeyName); if( strSubkeyName.Compare(lpszAppName) ) { nHasAllItems++; continue; } else break; } regKey.Close(); if( nHasAllItems == dwIndex ) return FALSE; else { \*hKey = regKey.m\_hKey;// this causes debug assertion failure:m\_hKey!=0 return TRUE; }
}
I wrote this funx to check whether there's a particular installed app in the registry. After calling this funx, hKey is expected to be assigned the registry handle. But prob occurs as Ive indicated above.
-
How are you calling
checkExistence()
? Aso, have you considered something a little more manageable, like:BOOL checkExistence( HKEY *hKey, LPCTSTR lpszAppName )
{
CString strKey;
strKey.Format(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s"), lpszAppName);return RegOpenKey(HKEY\_LOCAL\_MACHINE, strKey, hKey) == ERROR\_SUCCESS;
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius