]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/registry.cpp
ODBC library is built when wxUSE_GUI=0, too
[wxWidgets.git] / src / msw / registry.cpp
index 7d8a62aca13ca32c58dbd84010e063d89aab04d1..8305c63eb8f03e0233ff9cbe413eec135d388f2e 100644 (file)
@@ -12,7 +12,7 @@
 //              - add high level functions (RegisterOleServer, ...)
 ///////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 #pragma implementation "registry.h"
 #endif
 
@@ -36,7 +36,7 @@
 #define   WIN32_LEAN_AND_MEAN
 */
 
-#include  <windows.h>
+#include  "wx/msw/wrapwin.h"
 
 #ifdef __WXWINCE__
 #include "wx/msw/private.h"
@@ -94,7 +94,7 @@ aStdKeys[] =
 
 // useful for Windows programmers: makes somewhat more clear all these zeroes
 // being passed to Windows APIs
-#define   RESERVED        (NULL)
+#define   RESERVED        (0)
 
 // ----------------------------------------------------------------------------
 // macros
@@ -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;
@@ -867,14 +872,12 @@ bool wxRegKey::QueryValue(const wxChar *szValue,
             strValue.Empty();
         }
         else {
-            RegString pBuf = (RegString)strValue.GetWriteBuf(dwSize);
             m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
                                             WXSTRINGCAST szValue,
                                             RESERVED,
                                             &dwType,
-                                            pBuf,
+                                            (RegString)(wxChar*)wxStringBuffer(strValue, dwSize),
                                             &dwSize);
-            strValue.UngetWriteBuf();
 
             // expand the var expansions in the string unless disabled
 #ifndef __WXWINCE__
@@ -888,10 +891,9 @@ bool wxRegKey::QueryValue(const wxChar *szValue,
                     ok = ::ExpandEnvironmentStrings
                            (
                             strValue,
-                            strExpValue.GetWriteBuf(dwExpSize),
+                            wxStringBuffer(strExpValue, dwExpSize),
                             dwExpSize
                            ) != 0;
-                    strExpValue.UngetWriteBuf();
                     strValue = strExpValue;
                 }
 
@@ -1083,16 +1085,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;
 }