From: Vadim Zeitlin Date: Sat, 12 Jul 2003 14:18:04 +0000 (+0000) Subject: fixed incorrect RegOpenKeyEx() usage X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/8a8c41dd9315f3ed4aa287bd439bdd0a2c650458 fixed incorrect RegOpenKeyEx() usage git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21920 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index 7d8a62aca1..caf1a31d15 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -376,31 +376,36 @@ bool wxRegKey::GetKeyInfo(size_t *pnSubKeys, // opens key (it's not an error to call Open() on an already opened key) bool wxRegKey::Open() { - if ( IsOpened() ) - return TRUE; + if ( IsOpened() ) + return TRUE; + + HKEY tmpKey; + m_dwLastError = ::RegOpenKeyEx + ( + (HKEY) m_hRootKey, + m_strKey, + RESERVED, + KEY_ALL_ACCESS, + &tmpKey + ); + + if ( m_dwLastError != ERROR_SUCCESS ) + { + wxLogSysError(m_dwLastError, _("Can't open registry key '%s'"), + GetName().c_str()); + return FALSE; + } - HKEY tmpKey; - m_dwLastError = RegOpenKeyEx((HKEY) m_hRootKey, m_strKey, - 0, 0, &tmpKey); - if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, _("Can't open registry key '%s'"), - GetName().c_str()); - return FALSE; - } - else - { m_hKey = (WXHKEY) tmpKey; return TRUE; - } } // creates key, failing if it exists and !bOkIfExists bool wxRegKey::Create(bool bOkIfExists) { // check for existence only if asked (i.e. order is important!) - if ( !bOkIfExists && Exists() ) { + if ( !bOkIfExists && Exists() ) return FALSE; - } if ( IsOpened() ) return TRUE; @@ -1083,16 +1088,25 @@ bool wxRegKey::IsNumericValue(const wxChar *szValue) const bool KeyExists(WXHKEY hRootKey, const wxChar *szKey) { - // don't close this key itself for the case of empty szKey! - if ( wxIsEmpty(szKey) ) - return TRUE; + // don't close this key itself for the case of empty szKey! + if ( wxIsEmpty(szKey) ) + return TRUE; + + HKEY hkeyDummy; + if ( ::RegOpenKeyEx + ( + (HKEY)hRootKey, + szKey, + RESERVED, + KEY_ALL_ACCESS, + &hkeyDummy + ) == ERROR_SUCCESS ) + { + ::RegCloseKey(hkeyDummy); + + return TRUE; + } - HKEY hkeyDummy; - if ( RegOpenKeyEx( (HKEY) hRootKey, szKey, 0, 0, &hkeyDummy) == ERROR_SUCCESS ) { - RegCloseKey(hkeyDummy); - return TRUE; - } - else return FALSE; }