File: registry.h

package info (click to toggle)
wxwidgets3.0 3.0.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 120,808 kB
  • ctags: 118,010
  • sloc: cpp: 889,420; makefile: 52,980; ansic: 21,933; sh: 5,603; python: 2,935; xml: 1,534; perl: 281
file content (411 lines) | stat: -rw-r--r-- 12,233 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/////////////////////////////////////////////////////////////////////////////
// Name:        msw/registry.h
// Purpose:     interface of wxRegKey
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    @class wxRegKey

    wxRegKey is a class representing the Windows registry (it is only available
    under Windows). One can create, query and delete registry keys using this
    class.

    The Windows registry is easy to understand. There are five registry keys,
    namely:

    @li @c HKEY_CLASSES_ROOT (HKCR)
    @li @c HKEY_CURRENT_USER (HKCU)
    @li @c HKEY_LOCAL_MACHINE (HKLM)
    @li @c HKEY_CURRENT_CONFIG (HKCC)
    @li @c HKEY_USERS (HKU)

    After creating a key, it can hold a value. The values can be:

    @li String Value
    @li Binary Value
    @li DWORD Value
    @li Multi String Value
    @li Expandable String Value

    @onlyfor{wxmsw}

    @b Example:

    @code
    // This assume that the key already exists, use HasSubKey() to check
    // for the key existence if necessary.
    wxRegKey key(wxRegKey::HKLM, "Software\\MyKey");

    // Create a new value "MyValue" and set it to 12.
    key.SetValue("MyValue", 12);

    // Read the value back.
    long value;
    key.QueryValue("MyValue", &value);
    wxMessageBox(wxString::Format("%d", value), "Registry Value", wxOK);

    // Get the number of subkeys and enumerate them.
    size_t subkeys;
    key.GetKeyInfo(&subkeys, NULL, NULL, NULL);

    wxString key_name;
    key.GetFirstKey(key_name, 1);
    for(int i = 0; i < subkeys; i++)
    {
        wxMessageBox(key_name, "Subkey Name", wxOK);
        key.GetNextKey(key_name, 1);
    }
    @endcode


    @library{wxbase}
    @category{cfg}
*/
class wxRegKey
{
public:
    /**
        Default constructor, initializes to @c HKEY_CLASSES_ROOT.

        The @a viewMode parameter is new since wxWidgets 2.9.2.
    */
    wxRegKey(WOW64ViewMode viewMode = WOW64ViewMode_Default);
    /**
        The constructor to set the full name of the key.

        The @a viewMode parameter is new since wxWidgets 2.9.2.
    */
    wxRegKey(const wxString& strKey,
        WOW64ViewMode viewMode = WOW64ViewMode_Default);
    /**
        The constructor to set the full name of the key using one of the
        standard keys, that is, HKCR, HKCU, HKLM, HKUSR, HKPD, HKCC or HKDD.
        The @a viewMode parameter is new since wxWidgets 2.9.2.
    */
    wxRegKey(StdKey keyParent, const wxString& strKey,
        WOW64ViewMode viewMode = WOW64ViewMode_Default);
    /**
        The constructor to set the full name of the key under a previously
        created parent. The registry view is inherited from the parent.
    */
    wxRegKey(const wxRegKey& keyParent, const wxString& strKey);

    /**
        Access modes for wxRegKey.
    */
    enum AccessMode
    {
        Read, ///< Read-only
        Write ///< Read and Write
    };

    /**
        The standard registry key enumerator.
    */
    enum StdKey
    {
    HKCR,  ///< HKEY_CLASSES_ROOT
    HKCU,  ///< HKEY_CURRENT_USER
    HKLM,  ///< HKEY_LOCAL_MACHINE
    HKUSR, ///< HKEY_USERS
    HKPD,  ///< HKEY_PERFORMANCE_DATA (Windows NT and 2K only)
    HKCC,  ///< HKEY_CURRENT_CONFIG
    HKDD,  ///< HKEY_DYN_DATA (Windows 95 and 98 only)
    HKMAX
    };

    /**
        The value type enumerator.
    */
    enum ValueType
    {
    Type_None,                ///< No value type
    Type_String,              ///< Unicode null-terminated string
    Type_Expand_String,       ///< Unicode null-terminated string
                              ///< (with environment variable references)
    Type_Binary,              ///< Free form binary
    Type_Dword,               ///< 32-bit number
    Type_Dword_little_endian, ///< 32-bit number (same as Type_Dword)
    Type_Dword_big_endian,    ///< 32-bit number
    Type_Link,                ///< Symbolic Link (Unicode)
    Type_Multi_String,        ///< Multiple Unicode strings
    Type_Resource_list,       ///< Resource list in the resource map
    Type_Full_resource_descriptor,  ///< Resource list in the hardware description
    Type_Resource_requirements_list ///<
    };

    /**
        Used to determine how the registry will be viewed, either as
        32-bit or 64-bit.

        @since 2.9.2
    */
    enum WOW64ViewMode
    {
        /**
            Uses 32-bit registry for 32-bit applications and
            64-bit registry for 64-bit ones.
        */
        WOW64ViewMode_Default,

        /**
            Can be used in 64-bit apps to access the 32-bit registry,
            has no effect (i.e. treated as default) in 32-bit apps.
        */
        WOW64ViewMode_32,

        /**
            Can be used in 32-bit apps to access the 64-bit registry,
            has no effect (i.e. treated as default) in 64-bit apps.
        */
        WOW64ViewMode_64
    };

    /**
        Closes the key.
    */
    void Close();

    /**
        Copy the entire contents of the key recursively to another location
        using the name. Returns @true if successful.
    */
    bool Copy(const wxString& szNewName);
    /**
        Copy the entire contents of the key recursively to another location
        using the key. Returns @true if successful.
    */
    bool Copy(wxRegKey& keyDst);

    /**
        Copy the value to another key, possibly changing its name. By default
        it will remain the same. Returns @true if successful.
    */
    bool CopyValue(const wxString& szValue, wxRegKey& keyDst,
                  const wxString& szNewName = wxEmptyString);
    /**
        Creates the key. Will fail if the key already exists and @a bOkIfExists
        is @false. Returns @true if successful.
    */
    bool Create(bool bOkIfExists = true);

    /**
        Deletes the subkey with all its subkeys and values recursively.
    */
    void DeleteKey(const wxString& szKey);

    /**
        Deletes this key and all its subkeys and values recursively.
    */
    void DeleteSelf();

    /**
        Deletes the named value or use an empty string argument to remove the
        default value of the key.
    */
    void DeleteValue(const wxString& szKey);

    /**
        Returns @true if the key exists.
    */
    bool Exists() const;

    /**
        Write the contents of this key and all its subkeys to the given file.
        (The file will not be overwritten; it's an error if it already exists.)
        Note that we export the key in REGEDIT4 format, not RegSaveKey() binary
        format nor the newer REGEDIT5. Returns @true if successful.
    */
    bool Export(const wxString& filename) const;
    /**
        Write the contents of this key and all its subkeys to the opened stream.
        Returns @true if successful.
    */
    bool Export(wxOutputStream& ostr) const;

    /**
        Gets the first key. Returns @true if successful.
    */
    bool GetFirstKey(wxString& strKeyName, long& lIndex);

    /**
        Gets the first value of this key. Returns @true if successful.
    */
    bool GetFirstValue(wxString& strValueName, long& lIndex);

    /**
        Gets information about the key. Returns @true if successful.

        @param pnSubKeys
            The number of subkeys.
        @param pnMaxKeyLen
            The maximum length of the subkey name.
        @param pnValues
            The number of values.
        @param pnMaxValueLen
            The maximum length of a value.
    */
    bool GetKeyInfo(size_t* pnSubKeys, size_t* pnMaxKeyLen,
                    size_t* pnValues, size_t* pnMaxValueLen) const;

    /**
        Gets the name of the registry key.
    */
    wxString GetName(bool bShortPrefix = true) const;

    /**
        Retrieves the registry view used by this key.

        @since 2.9.2

        @return The registry view given at the object's construction.
    */
    WOW64ViewMode GetView() const { return m_viewMode; }

    /**
        Gets the next key. Returns @true if successful.
    */
    bool GetNextKey(wxString& strKeyName, long& lIndex) const;

    /**
        Gets the next key value for this key. Returns @true if successful.
    */
    bool GetNextValue(wxString& strValueName, long& lIndex) const;

    /**
        Gets the value type.
    */
    ValueType GetValueType(const wxString& szValue) const;

    /**
        Returns @true if given subkey exists.
    */
    bool HasSubKey(const wxString& szKey) const;

    /**
        Returns @true if any subkeys exist.
    */
    bool HasSubkeys() const;

    /**
        Returns @true if the value exists.
    */
    bool HasValue(const wxString& szValue) const;

    /**
        Returns @true if any values exist.
    */
    bool HasValues() const;

    /**
        Returns @true if this key is empty, nothing under this key.
    */
    bool IsEmpty() const;

    /**
        Returns @true if the value contains a number.
    */
    bool IsNumericValue(const wxString& szValue) const;

    /**
        Returns @true if the key is opened.
    */
    bool IsOpened() const;

    /**
        Explicitly opens the key. This method also allows the key to be opened
        in read-only mode by passing wxRegKey::Read instead of default
        wxRegKey::Write parameter. Returns @true if successful.
    */
    bool Open(AccessMode mode = Write);

    /**
        Assignment operator to set the default value of the key.
    */
    wxRegKey& operator=(const wxString& strValue);

    /**
        Return the default value of the key.
    */
    wxString QueryDefaultValue() const;

    /**
        Retrieves the raw string value. Returns @true if successful.
        An empty @a szValue queries the default/unnamed key value.
    */
    bool QueryRawValue(const wxString& szValue, wxString& strValue) const;

    /**
        Retrieves the raw or expanded string value. Returns @true if successful.
        An empty @a szValue queries the default/unnamed key value.
    */
    bool QueryValue(const wxString& szValue, wxString& strValue, bool raw) const;

    /**
        Retrieves the numeric value. Returns @true if successful.
        An empty @a szValue queries the default/unnamed key value.
    */
    bool QueryValue(const wxString& szValue, long* plValue) const;

    /**
        Retrieves the binary structure. Returns @true if successful.
        An empty @a szValue queries the default/unnamed key value.
    */
    bool QueryValue(const wxString& szValue, wxMemoryBuffer& buf) const;

    /**
        Renames the key. Returns @true if successful.
    */
    bool Rename(const wxString& szNewName);

    /**
        Renames a value. Returns @true if successful.
    */
    bool RenameValue(const wxString& szValueOld,
                     const wxString& szValueNew);

    /**
        Preallocate some memory for the name. For wxRegConfig usage only.
    */
    void ReserveMemoryForName(size_t bytes);

    /**
        Set or change the HKEY handle.
    */
    void SetHkey(WXHKEY hKey);

    /**
        Set the full key name. The name is absolute. It should start with
        HKEY_xxx.
    */
    void SetName(const wxString& strKey);
    /**
        Set the name relative to the parent key
    */
    void SetName(StdKey keyParent, const wxString& strKey);
    /**
        Set the name relative to the parent key
    */
    void SetName(const wxRegKey& keyParent, const wxString& strKey);

    /**
        Sets the given @a szValue which must be numeric. If the value doesn't
        exist, it is created. Returns @true if successful.
        An empty @a szValue sets the default/unnamed key value.
    */
    bool SetValue(const wxString& szValue, long lValue);
    /**
        Sets the given @a szValue which must be string. If the value doesn't
        exist, it is created. Returns @true if successful.
        An empty @a szValue sets the default/unnamed key value.
    */
    bool SetValue(const wxString& szValue, const wxString& strValue);
    /**
        Sets the given @a szValue which must be binary. If the value doesn't
        exist, it is created. Returns @true if successful.
        An empty @a szValue sets the default/unnamed key value.
    */
    bool SetValue(const wxString& szValue, const wxMemoryBuffer& buf);
};