Firstly, this is a legacy project, very old, I have the short straw of bringing it up to date.
I noticed that one of the errors is that the application relies on registry structure already existing. I want to test the structure is present and if not create any missing keys.
There is a existing class called CRegKey, the Open method:
inline LONG CRegKey::Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired) throw() {
ATLASSUME(hKeyParent != NULL);
HKEY hKey = NULL;
LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyName, 0, samDesired, &hKey);
if (lRes == ERROR_SUCCESS) {
lRes = Close();
ATLASSERT(lRes == ERROR_SUCCESS);
m_hKey = hKey;
#if WINVER >= 0x0501
m_samWOW64 = samDesired & (KEY_WOW64_32KEY | KEY_WOW64_64KEY);
#endif
}
return lRes;
}
The problem is that I've found then when calling this routine, if the key doesn't exist it returns ERROR_SUCCESS, a typical example:
DWORD dwRes = rKey.Open(HKEY_LOCAL_MACHINE, szPath, KEY_READ);
In the above example szPath has a value of:
SOFTWARE\Name\Scada\LonAgent
I've exported the original registry and for test purposes have deleted the 'LonAgent' key.
The problem is that although this key doesn't exist, dwRes is still 0 which is the same as ERROR_SUCCESS....why?