// - add high level functions (RegisterOleServer, ...)
///////////////////////////////////////////////////////////////////////////////
// - add high level functions (RegisterOleServer, ...)
///////////////////////////////////////////////////////////////////////////////
{ 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?
#endif //GNUWIN32
#endif //WINVER >= 4.0
{ HKEY_DYN_DATA, wxT("HKEY_DYN_DATA"), wxT("HKDD") }, // short name?
#endif //GNUWIN32
#endif //WINVER >= 4.0
// useful for Windows programmers: makes somewhat more clear all these zeroes
// being passed to Windows APIs
// useful for Windows programmers: makes somewhat more clear all these zeroes
// being passed to Windows APIs
// old gcc headers incorrectly prototype RegQueryInfoKey()
#if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
// old gcc headers incorrectly prototype RegQueryInfoKey()
#if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
// ----------------------------------------------------------------------------
// opens key (it's not an error to call Open() on an already opened key)
// ----------------------------------------------------------------------------
// opens key (it's not an error to call Open() on an already opened key)
- if ( IsOpened() )
- return TRUE;
+ if ( IsOpened() )
+ return TRUE;
+
+ HKEY tmpKey;
+ m_dwLastError = ::RegOpenKeyEx
+ (
+ (HKEY) m_hRootKey,
+ m_strKey,
+ RESERVED,
+ mode == Read ? KEY_READ : 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 = RegOpenKey((HKEY) m_hRootKey, m_strKey, &tmpKey);
- if ( m_dwLastError != ERROR_SUCCESS ) {
- wxLogSysError(m_dwLastError, _("Can't open registry key '%s'"),
- GetName().c_str());
- return FALSE;
- }
- else
- {
}
// creates key, failing if it exists and !bOkIfExists
bool wxRegKey::Create(bool bOkIfExists)
{
// check for existence only if asked (i.e. order is important!)
}
// 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 ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't create registry key '%s'"),
GetName().c_str());
if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't create registry key '%s'"),
GetName().c_str());
wxLogSysError(m_dwLastError, _("Can't delete value '%s' from key '%s'"),
szValue, GetName().c_str());
return FALSE;
}
wxLogSysError(m_dwLastError, _("Can't delete value '%s' from key '%s'"),
szValue, GetName().c_str());
return FALSE;
}
if ( CONST_CAST Open() ) {
m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_DWORD,
(RegString)&lValue, sizeof(lValue));
if ( CONST_CAST Open() ) {
m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_DWORD,
(RegString)&lValue, sizeof(lValue));
wxLogSysError(m_dwLastError, _("Can't set value of '%s'"),
GetFullName(this, szValue));
return FALSE;
wxLogSysError(m_dwLastError, _("Can't set value of '%s'"),
GetFullName(this, szValue));
return FALSE;
if ( (dwType == REG_EXPAND_SZ) && !raw )
{
DWORD dwExpSize = ::ExpandEnvironmentStrings(strValue, NULL, 0);
if ( (dwType == REG_EXPAND_SZ) && !raw )
{
DWORD dwExpSize = ::ExpandEnvironmentStrings(strValue, NULL, 0);
bool wxRegKey::SetValue(const wxChar *szValue, const wxString& strValue)
{
if ( CONST_CAST Open() ) {
bool wxRegKey::SetValue(const wxChar *szValue, const wxString& strValue)
{
if ( CONST_CAST Open() ) {
m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_SZ,
(RegString)strValue.c_str(),
(strValue.Len() + 1)*sizeof(wxChar));
if ( m_dwLastError == ERROR_SUCCESS )
return TRUE;
m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_SZ,
(RegString)strValue.c_str(),
(strValue.Len() + 1)*sizeof(wxChar));
if ( m_dwLastError == ERROR_SUCCESS )
return TRUE;
// named registry values don't exist in Win16
wxASSERT( IsEmpty(szValue) );
m_dwLastError = RegSetValue((HKEY) m_hKey, NULL, REG_SZ, strValue, NULL);
if ( m_dwLastError == ERROR_SUCCESS )
return TRUE;
// named registry values don't exist in Win16
wxASSERT( IsEmpty(szValue) );
m_dwLastError = RegSetValue((HKEY) m_hKey, NULL, REG_SZ, strValue, NULL);
if ( m_dwLastError == ERROR_SUCCESS )
return TRUE;
m_dwLastError = RegEnumKey((HKEY) m_hKey, lIndex++, szKeyName, WXSIZEOF(szKeyName));
m_dwLastError = RegEnumKey((HKEY) m_hKey, lIndex++, szKeyName, WXSIZEOF(szKeyName));
- // 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_READ, // we might not have enough rights for rw access
+ &hkeyDummy
+ ) == ERROR_SUCCESS )
+ {
+ ::RegCloseKey(hkeyDummy);
+
+ return TRUE;
+ }