]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/registry.cpp
Ensure there is valid context for DrawRectangle
[wxWidgets.git] / src / msw / registry.cpp
index eb666c56f842a5aa3cbaff9d6c3818bd03e40921..144009b810b7cf2f9a08144b8faa65f3a745c1b8 100644 (file)
 #include "wx/dynlib.h"
 #include "wx/file.h"
 #include "wx/wfstream.h"
+#include "wx/msw/private.h"
 
 // Windows headers
 #ifdef __WXWINCE__
-#include "wx/msw/private.h"
 #include <winbase.h>
 #include <winreg.h>
 #endif
@@ -326,7 +326,7 @@ void wxRegKey::SetHkey(WXHKEY hKey)
   m_mode = Write;
 
   // reset old data
-  m_strKey.empty();
+  m_strKey.clear();
   m_dwLastError = 0;
 }
 
@@ -360,36 +360,57 @@ bool wxRegKey::GetKeyInfo(size_t *pnSubKeys,
                           size_t *pnValues,
                           size_t *pnMaxValueLen) const
 {
-    // old gcc headers incorrectly prototype RegQueryInfoKey()
-#if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
-    #define REG_PARAM   (size_t *)
-#else
-    #define REG_PARAM   (LPDWORD)
-#endif
-
   // it might be unexpected to some that this function doesn't open the key
   wxASSERT_MSG( IsOpened(), wxT("key should be opened in GetKeyInfo") );
 
+  // We need to use intermediate variables in 64 bit build as the function
+  // parameters must be 32 bit DWORDs and not 64 bit size_t values.
+#ifdef __WIN64__
+  DWORD dwSubKeys = 0,
+        dwMaxKeyLen = 0,
+        dwValues = 0,
+        dwMaxValueLen = 0;
+
+  #define REG_PARAM(name) &dw##name
+#else // Win32
+  // Old gcc headers incorrectly prototype RegQueryInfoKey() as taking
+  // size_t but normally we need a cast, even when sizeof(size_t) is the same
+  // as sizeof(DWORD).
+  #if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
+    #define REG_PARAM(name) pn##name
+  #else
+    #define REG_PARAM(name)   (LPDWORD)(pn##name)
+  #endif
+#endif
+
+
   m_dwLastError = ::RegQueryInfoKey
                   (
                     (HKEY) m_hKey,
-                    NULL,           // class name
-                    NULL,           // (ptr to) size of class name buffer
+                    NULL,                   // class name
+                    NULL,                   // (ptr to) size of class name buffer
                     RESERVED,
-                    REG_PARAM
-                    pnSubKeys,      // [out] number of subkeys
-                    REG_PARAM
-                    pnMaxKeyLen,    // [out] max length of a subkey name
-                    NULL,           // longest subkey class name
-                    REG_PARAM
-                    pnValues,       // [out] number of values
-                    REG_PARAM
-                    pnMaxValueLen,  // [out] max length of a value name
-                    NULL,           // longest value data
-                    NULL,           // security descriptor
-                    NULL            // time of last modification
+                    REG_PARAM(SubKeys),     // [out] number of subkeys
+                    REG_PARAM(MaxKeyLen),   // [out] max length of a subkey name
+                    NULL,                   // longest subkey class name
+                    REG_PARAM(Values),      // [out] number of values
+                    REG_PARAM(MaxValueLen), // [out] max length of a value name
+                    NULL,                   // longest value data
+                    NULL,                   // security descriptor
+                    NULL                    // time of last modification
                   );
 
+#ifdef __WIN64__
+  if ( pnSubKeys )
+    *pnSubKeys = dwSubKeys;
+  if ( pnMaxKeyLen )
+    *pnMaxKeyLen = dwMaxKeyLen;
+  if ( pnValues )
+    *pnValues = dwValues;
+  if ( pnMaxValueLen )
+    *pnMaxValueLen = dwMaxValueLen;
+#endif // __WIN64__
+
 #undef REG_PARAM
 
   if ( m_dwLastError != ERROR_SUCCESS ) {
@@ -1036,7 +1057,7 @@ bool wxRegKey::SetValue(const wxString& szValue, const wxString& strValue)
       m_dwLastError = RegSetValueEx((HKEY) m_hKey,
                                     RegValueStr(szValue),
                                     (DWORD) RESERVED, REG_SZ,
-                                    (RegString)strValue.t_str(),
+                                    (RegString)wxMSW_CONV_LPCTSTR(strValue),
                                     (strValue.Len() + 1)*sizeof(wxChar));
       if ( m_dwLastError == ERROR_SUCCESS )
         return true;
@@ -1214,7 +1235,7 @@ bool wxRegKey::Export(const wxString& filename) const
 
     wxFFileOutputStream ostr(filename, wxT("w"));
 
-    return ostr.Ok() && Export(ostr);
+    return ostr.IsOk() && Export(ostr);
 #else
     wxUnusedVar(filename);
     return false;