cleanup
This commit is contained in:
@@ -462,21 +462,26 @@ int CRegistry::ReadInt(CString strName, int nDefault)
|
||||
return n;
|
||||
}
|
||||
|
||||
BOOL CRegistry::ReadBool(CString strName, BOOL bDefault)
|
||||
bool CRegistry::Read(CString strName, bool &result)
|
||||
{
|
||||
DWORD dwType = REG_BINARY;
|
||||
ASSERT(m_strCurrentPath.GetLength() > 0);
|
||||
HKEY hKey;
|
||||
if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0,
|
||||
KEY_READ, &hKey) != ERROR_SUCCESS)
|
||||
return false;
|
||||
|
||||
BOOL b;
|
||||
DWORD dwSize = sizeof(b);
|
||||
HKEY hKey;
|
||||
|
||||
ASSERT(m_strCurrentPath.GetLength() > 0);
|
||||
if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0,
|
||||
KEY_READ, &hKey) != ERROR_SUCCESS) return bDefault;
|
||||
|
||||
if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL,
|
||||
&dwType, (LPBYTE)&b, &dwSize) != ERROR_SUCCESS) b = bDefault;
|
||||
DWORD dwType = REG_BINARY;
|
||||
int ret = ::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, &dwType, (LPBYTE)&b, &dwSize);
|
||||
::RegCloseKey(hKey);
|
||||
return b;
|
||||
|
||||
if ( ret != ERROR_SUCCESS )
|
||||
return false;
|
||||
|
||||
result = !!b;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -588,7 +593,8 @@ BOOL CRegistry::WriteBool(CString strName, BOOL bValue)
|
||||
REG_BINARY, (LPBYTE)&bValue, sizeof(bValue))
|
||||
!= ERROR_SUCCESS) bSuccess = FALSE;
|
||||
|
||||
if (!m_bLazyWrite) ::RegFlushKey(hKey);
|
||||
if (!m_bLazyWrite)
|
||||
::RegFlushKey(hKey);
|
||||
::RegCloseKey(hKey);
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
|
||||
|
||||
#ifndef __REGISTRY_H__
|
||||
#define __REGISTRY_H__
|
||||
#ifndef REGISTRY_H
|
||||
#define REGISTRY_H
|
||||
|
||||
class CRegistry
|
||||
{
|
||||
@@ -9,7 +7,7 @@ public:
|
||||
CRegistry();
|
||||
~CRegistry();
|
||||
|
||||
int m_nLastError;
|
||||
int m_nLastError;
|
||||
|
||||
// CRegistry properties
|
||||
protected:
|
||||
@@ -18,15 +16,10 @@ protected:
|
||||
CString m_strCurrentPath;
|
||||
|
||||
public:
|
||||
inline BOOL PathIsValid() {
|
||||
return (m_strCurrentPath.GetLength() > 0); }
|
||||
inline CString GetCurrentPath() {
|
||||
return m_strCurrentPath; }
|
||||
inline HKEY GetRootKey() {
|
||||
return m_hRootKey; }
|
||||
inline BOOL PathIsValid() const { return m_strCurrentPath.GetLength() > 0; }
|
||||
inline CString GetCurrentPath() const { return m_strCurrentPath; }
|
||||
inline HKEY GetRootKey() const { return m_hRootKey; }
|
||||
|
||||
|
||||
//CRegistry methods
|
||||
public:
|
||||
BOOL ClearKey();
|
||||
BOOL SetRootKey(HKEY hRootKey);
|
||||
@@ -55,6 +48,10 @@ public:
|
||||
BOOL ReadRect(CString strName, CRect* pRect);
|
||||
DWORD ReadDword(CString strName, DWORD dwDefault);
|
||||
|
||||
/* Readers converted to a less silly mechanism below (do these as needed):
|
||||
* return the value in result if found, otherwise return false. */
|
||||
bool Read(CString strName, bool &result);
|
||||
|
||||
// data writing functions
|
||||
BOOL WriteBool(CString strName, BOOL bValue);
|
||||
BOOL WriteDateTime(CString strName, COleDateTime dtValue);
|
||||
|
||||
Reference in New Issue
Block a user