+#ifndef HKEY_PERFORMANCE_DATA
+ #define HKEY_PERFORMANCE_DATA ((HKEY)0x80000004)
+#endif
+
+#ifndef HKEY_CURRENT_CONFIG
+ #define HKEY_CURRENT_CONFIG ((HKEY)0x80000005)
+#endif
+
+#ifndef HKEY_DYN_DATA
+ #define HKEY_DYN_DATA ((HKEY)0x80000006)
+#endif
+
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
{ HKEY_CURRENT_USER, wxT("HKEY_CURRENT_USER"), wxT("HKCU") },
{ HKEY_LOCAL_MACHINE, wxT("HKEY_LOCAL_MACHINE"), wxT("HKLM") },
{ HKEY_USERS, wxT("HKEY_USERS"), wxT("HKU") }, // short name?
{ HKEY_CURRENT_USER, wxT("HKEY_CURRENT_USER"), wxT("HKCU") },
{ HKEY_LOCAL_MACHINE, wxT("HKEY_LOCAL_MACHINE"), wxT("HKLM") },
{ HKEY_USERS, wxT("HKEY_USERS"), wxT("HKU") }, // short name?
{ HKEY_PERFORMANCE_DATA, wxT("HKEY_PERFORMANCE_DATA"), wxT("HKPD") },
{ HKEY_PERFORMANCE_DATA, wxT("HKEY_PERFORMANCE_DATA"), wxT("HKPD") },
{ HKEY_CURRENT_CONFIG, wxT("HKEY_CURRENT_CONFIG"), wxT("HKCC") },
{ HKEY_CURRENT_CONFIG, wxT("HKEY_CURRENT_CONFIG"), wxT("HKCC") },
{ HKEY_DYN_DATA, wxT("HKEY_DYN_DATA"), wxT("HKDD") }, // short name?
{ HKEY_DYN_DATA, wxT("HKEY_DYN_DATA"), wxT("HKDD") }, // short name?
static inline void RemoveTrailingSeparator(wxString& str);
// returns true if given registry key exists
static inline void RemoveTrailingSeparator(wxString& str);
// returns true if given registry key exists
-static bool KeyExists(WXHKEY hRootKey, const wxChar *szKey);
+static bool KeyExists(WXHKEY hRootKey, const wxString& szKey);
+
+// combines value and key name
+static wxString GetFullName(const wxRegKey *pKey);
+static wxString GetFullName(const wxRegKey *pKey, const wxString& szValue);
-// combines value and key name (uses static buffer!)
-static const wxChar *GetFullName(const wxRegKey *pKey,
- const wxChar *szValue = NULL);
+// returns "value" argument of wxRegKey methods converted into a value that can
+// be passed to win32 registry functions; specifically, converts empty string
+// to NULL
+static inline const wxChar *RegValueStr(const wxString& szValue);
// ============================================================================
// implementation of wxRegKey class
// ============================================================================
// implementation of wxRegKey class
bool wxRegKey::Exists() const
{
// opened key has to exist, try to open it if not done yet
bool wxRegKey::Exists() const
{
// opened key has to exist, try to open it if not done yet
#endif
if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't create registry key '%s'"),
#endif
if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't create registry key '%s'"),
wxRegKey key(*this, strKey);
wxString keyName;
keyName << GetFullName(&keyDst) << REG_SEPARATOR << strKey;
wxRegKey key(*this, strKey);
wxString keyName;
keyName << GetFullName(&keyDst) << REG_SEPARATOR << strKey;
// deleting a key which doesn't exist is not considered an error
if ( m_dwLastError != ERROR_SUCCESS &&
m_dwLastError != ERROR_FILE_NOT_FOUND ) {
// deleting a key which doesn't exist is not considered an error
if ( m_dwLastError != ERROR_SUCCESS &&
m_dwLastError != ERROR_FILE_NOT_FOUND ) {
// deleting a value which doesn't exist is not considered an error
if ( (m_dwLastError != ERROR_SUCCESS) &&
// deleting a value which doesn't exist is not considered an error
if ( (m_dwLastError != ERROR_SUCCESS) &&
// ----------------------------------------------------------------------------
// return true if value exists
// ----------------------------------------------------------------------------
// return true if value exists
- m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED,
+ m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue), RESERVED,
&dwType, NULL, NULL);
if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"),
&dwType, NULL, NULL);
if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"),
- m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_DWORD,
+ m_dwLastError = RegSetValueEx((HKEY) m_hKey, RegValueStr(szValue),
+ (DWORD) RESERVED, REG_DWORD,
(RegString)&lValue, sizeof(lValue));
if ( m_dwLastError == ERROR_SUCCESS )
return true;
(RegString)&lValue, sizeof(lValue));
if ( m_dwLastError == ERROR_SUCCESS )
return true;
{
if ( CONST_CAST Open(Read) ) {
DWORD dwType, dwSize = sizeof(DWORD);
RegString pBuf = (RegString)plValue;
{
if ( CONST_CAST Open(Read) ) {
DWORD dwType, dwSize = sizeof(DWORD);
RegString pBuf = (RegString)plValue;
- m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED,
+ m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue),
+ RESERVED,
&dwType, pBuf, &dwSize);
if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"),
&dwType, pBuf, &dwSize);
if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"),
- m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_BINARY,
+ m_dwLastError = RegSetValueEx((HKEY) m_hKey, RegValueStr(szValue),
+ (DWORD) RESERVED, REG_BINARY,
(RegBinary)buffer.GetData(),buffer.GetDataLen());
if ( m_dwLastError == ERROR_SUCCESS )
return true;
(RegBinary)buffer.GetData(),buffer.GetDataLen());
if ( m_dwLastError == ERROR_SUCCESS )
return true;
- m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED,
- &dwType, NULL, &dwSize);
+ m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue),
+ RESERVED,
+ &dwType, NULL, &dwSize);
if ( m_dwLastError == ERROR_SUCCESS ) {
if ( dwSize ) {
const RegBinary pBuf = (RegBinary)buffer.GetWriteBuf(dwSize);
m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
if ( m_dwLastError == ERROR_SUCCESS ) {
if ( dwSize ) {
const RegBinary pBuf = (RegBinary)buffer.GetWriteBuf(dwSize);
m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
// first get the type and size of the data
DWORD dwType=REG_NONE, dwSize=0;
// first get the type and size of the data
DWORD dwType=REG_NONE, dwSize=0;
- m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_SZ,
- (RegString)strValue.c_str(),
+ m_dwLastError = RegSetValueEx((HKEY) m_hKey,
+ RegValueStr(szValue),
+ (DWORD) RESERVED, REG_SZ,
+ (RegString)strValue.wx_str(),
wxCharBuffer name(s.mb_str());
ostr.Write(name, strlen(name));
#else
wxCharBuffer name(s.mb_str());
ostr.Write(name, strlen(name));
#else
// implementation of global private functions
// ============================================================================
// implementation of global private functions
// ============================================================================
- static wxString s_str;
- s_str = pKey->GetName();
- if ( !wxIsEmpty(szValue) )
- s_str << wxT("\\") << szValue;
+ wxString str(pKey->GetName());
+ if ( !szValue.empty() )
+ str << wxT("\\") << szValue;
+
+ return str;
+}