1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/registry.h
3 // Purpose: Registry classes and functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
16 #pragma interface "registry.h"
19 // ----------------------------------------------------------------------------
20 // mutable hack (see also registry.cpp)
21 // ----------------------------------------------------------------------------
23 #define MUTABLE mutable
28 // ----------------------------------------------------------------------------
29 // types used in this module
30 // ----------------------------------------------------------------------------
33 #define HKEY unsigned long
36 typedef unsigned long ulong
;
38 // ----------------------------------------------------------------------------
39 // class wxRegKey encapsulates window HKEY handle
40 // ----------------------------------------------------------------------------
41 class WXDLLEXPORT wxRegKey
44 // NB: do _not_ change the values of elements in these enumerations!
46 // registry value types (with comments from winnt.h)
49 Type_None
, // No value type
50 Type_String
, // Unicode nul terminated string
52 Type_Expand_String
, // Unicode nul terminated string
53 // (with environment variable references)
54 Type_Binary
, // Free form binary
55 Type_Dword
, // 32-bit number
56 Type_Dword_little_endian
, // 32-bit number (same as Type_DWORD)
57 Type_Dword_big_endian
, // 32-bit number
58 Type_Link
, // Symbolic Link (unicode)
59 Type_Multi_String
, // Multiple Unicode strings
60 Type_Resource_list
, // Resource list in the resource map
61 Type_Full_resource_descriptor
, // Resource list in the hardware description
62 Type_Resource_requirements_list
, // ???
66 // predefined registry keys
72 HKLM
, // local machine
74 HKPD
, // performance data (@@ NT only?)
76 HKCC
, // current config
82 // information about standard (predefined) registry keys
83 // number of standard keys
84 static const size_t nStdKeys
;
85 // get the name of a standard key
86 static const char *GetStdKeyName(uint key
);
87 // get the short name of a standard key
88 static const char *GetStdKeyShortName(uint key
);
89 // get StdKey from root HKEY
90 static StdKey
GetStdKeyFromHkey(HKEY hkey
);
92 // extacts the std key prefix from the string (return value) and
93 // leaves only the part after it (i.e. modifies the string passed!)
94 static StdKey
ExtractKeyName(wxString
& str
);
97 // root key is set to HKCR (the only root key under Win16)
99 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
100 wxRegKey(const wxString
& strKey
);
101 // strKey is the name of key under (standard key) keyParent
102 wxRegKey(StdKey keyParent
, const wxString
& strKey
);
103 // strKey is the name of key under (previously created) keyParent
104 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
108 // change key (closes the previously opened key if any)
109 // the name is absolute, i.e. should start with HKEY_xxx
110 void SetName(const wxString
& strKey
);
111 // the name is relative to the parent key
112 void SetName(StdKey keyParent
, const wxString
& strKey
);
113 // the name is relative to the parent key
114 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
115 // hKey should be opened and will be closed in wxRegKey dtor
116 void SetHkey(HKEY hKey
);
118 // get infomation about the key
119 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
120 wxString
GetName(bool bShortPrefix
= TRUE
) const;
121 // return true if the key exists
123 // get the info about key (any number of these pointers may be NULL)
124 bool GetKeyInfo(ulong
*pnSubKeys
, // number of subkeys
125 ulong
*pnMaxKeyLen
, // max len of subkey name
126 ulong
*pnValues
, // number of values
127 ulong
*pnMaxValueLen
) const;
128 // return true if the key is opened
129 bool IsOpened() const { return m_hKey
!= 0; }
130 // for "if ( !key ) wxLogError(...)" kind of expressions
131 operator bool() const { return m_dwLastError
== 0; }
133 // operations on the key itself
134 // explicitly open the key (will be automatically done by all functions
135 // which need the key to be opened if the key is not opened yet)
137 // create the key: will fail if the key already exists and bOkIfExists
138 bool Create(bool bOkIfExists
= TRUE
);
139 // close the key (will be automatically done in dtor)
142 // deleting keys/values
143 // deletes this key and all of it's subkeys/values
145 // deletes the subkey with all of it's subkeys/values recursively
146 bool DeleteKey(const char *szKey
);
147 // deletes the named value (may be NULL to remove the default value)
148 bool DeleteValue(const char *szValue
);
150 // access to values and subkeys
152 ValueType
GetValueType(const char *szValue
);
154 // assignment operators set the default value of the key
155 wxRegKey
& operator=(const wxString
& strValue
)
156 { SetValue(NULL
, strValue
); return *this; }
157 wxRegKey
& operator=(long lValue
)
158 { SetValue(NULL
, lValue
); return *this; }
160 // conversion operators query the default value of the key
161 operator wxString() const;
163 // set the string value
164 bool SetValue(const char *szValue
, const wxString
& strValue
);
165 // return the string value
166 bool QueryValue(const char *szValue
, wxString
& strValue
) const;
169 // set the numeric value
170 bool SetValue(const char *szValue
, long lValue
);
171 // return the numeric value
172 bool QueryValue(const char *szValue
, long *plValue
) const;
175 // query existence of a key/value
176 // return true if value exists
177 bool HasValue(const char *szKey
) const;
178 // return true if given subkey exists
179 bool HasSubKey(const char *szKey
) const;
180 // return true if any subkeys exist
181 bool HasSubkeys() const;
183 // enumerate values and subkeys
184 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
185 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
187 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
188 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
191 // no copy ctor/assignment operator
192 wxRegKey(const wxRegKey
& key
); // not implemented
193 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
195 HKEY m_hKey
, // our handle
196 m_hRootKey
; // handle of the top key (i.e. StdKey)
197 wxString m_strKey
; // key name (relative to m_hRootKey)
199 MUTABLE
long m_dwLastError
; // last error (0 if none)