Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Omniifr::RegistryKey Class Reference

Opens a windows registry key, and closed it upon destruction. More...

List of all members.

Public Member Functions

 RegistryKey (RegistryKey &right)
 Copy constructor, adopts ownership.
 RegistryKey (HKEY hkey, const char *subkey, REGSAM samDesired=KEY_QUERY_VALUE)
 Constructor, opens the key.
 ~RegistryKey ()
 Destructor, closes the key.
 operator bool () const
int setValueStr (const char *name, const char *data)
char * queryValueStr (const char *name, const int maxlen=2048) const

Private Member Functions

 RegistryKey ()
 No implementation.
 RegistryKey (HKEY hkey, bool open=true)

Private Attributes

HKEY _hkey
bool _open


Detailed Description

Opens a windows registry key, and closed it upon destruction.

Upon failure, it emits an error message and then quits. Why do I have to write this class myself??

Definition at line 86 of file daemon_windows.cc.


Constructor & Destructor Documentation

Omniifr::RegistryKey::RegistryKey  )  [private]
 

No implementation.

Omniifr::RegistryKey::RegistryKey HKEY  hkey,
bool  open = true
[inline, private]
 

Definition at line 92 of file daemon_windows.cc.

References _hkey, and _open.

00092 :_hkey(hkey),_open(open){}

Omniifr::RegistryKey::RegistryKey RegistryKey right  ) 
 

Copy constructor, adopts ownership.

Definition at line 103 of file daemon_windows.cc.

00103                                           :
00104   _hkey(right._hkey),_open(right._open)
00105 {
00106   right._open=false;
00107 }

Omniifr::RegistryKey::RegistryKey HKEY  hkey,
const char *  subkey,
REGSAM  samDesired = KEY_QUERY_VALUE
 

Constructor, opens the key.

Definition at line 110 of file daemon_windows.cc.

References _hkey, and _open.

00114  :_hkey(), _open(false)
00115 {
00116   long ret=::RegOpenKeyEx(hkey,subkey,0,samDesired,&_hkey);
00117   ::SetLastError(ret);
00118   if(ret==ERROR_SUCCESS)
00119       _open=true;
00120 }

Omniifr::RegistryKey::~RegistryKey  ) 
 

Destructor, closes the key.

Definition at line 123 of file daemon_windows.cc.

References _hkey, _open, and HERE.

00124 {
00125   // Windows - why use two lines, when seven will do??
00126   // RegCloseKey() does not set last error, so complexity ensues...
00127   if(_open)
00128   {
00129     long ret =::RegCloseKey(_hkey);
00130     ::SetLastError(ret);
00131     if(ret!=ERROR_SUCCESS)
00132         Win::perror("Warning at " HERE);
00133   }
00134 }


Member Function Documentation

Omniifr::RegistryKey::operator bool  )  const [inline]
 

Definition at line 97 of file daemon_windows.cc.

References _open.

00097 { return _open; }

char * Omniifr::RegistryKey::queryValueStr const char *  name,
const int  maxlen = 2048
const
 

Definition at line 150 of file daemon_windows.cc.

References _hkey.

Referenced by Omniifr::Service::readParameters().

00151 {
00152   char* result =NULL;
00153   char* buf =new char[maxlen];
00154   DWORD len =maxlen;
00155 
00156   long ret=::RegQueryValueEx(_hkey,name,NULL,NULL,(LPBYTE)buf,&len);
00157   ::SetLastError(ret);
00158   if(ret==ERROR_SUCCESS && len<=maxlen)
00159       result=::strdup(buf); // MSVC6 has no strndup()!!
00160   delete[] buf;
00161   return result;
00162 }

int Omniifr::RegistryKey::setValueStr const char *  name,
const char *  data
 

Definition at line 136 of file daemon_windows.cc.

References _hkey.

Referenced by Omniifr::Service::install(), and Omniifr::Service::writeParameters().

00137 {
00138   long ret=::RegSetValueEx(
00139       _hkey,name,0,REG_SZ,
00140       (const BYTE*)(data),
00141       1+::strlen(data)
00142     );
00143   ::SetLastError(ret);
00144   if(ret==ERROR_SUCCESS)
00145       return 0;
00146   else
00147       return 1;
00148 }


Member Data Documentation

HKEY Omniifr::RegistryKey::_hkey [private]
 

Definition at line 88 of file daemon_windows.cc.

Referenced by queryValueStr(), RegistryKey(), setValueStr(), and ~RegistryKey().

bool Omniifr::RegistryKey::_open [private]
 

Definition at line 89 of file daemon_windows.cc.

Referenced by operator bool(), RegistryKey(), and ~RegistryKey().


The documentation for this class was generated from the following file:
Generated on Fri Mar 4 13:03:58 2005 for OmniIFR by  doxygen 1.4.1