blob: 68d535cdb8e3dc25febf22b99122db0058208fdf [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18// -=- Registry.h
19
20// C++ wrappers around the Win32 Registry APIs
21
22#ifndef __RFB_WIN32_REGISTRY_H__
23#define __RFB_WIN32_REGISTRY_H__
24
25#include <windows.h>
26#include <rfb_win32/Security.h>
27#include <rfb/util.h>
28
29namespace rfb {
30
31 namespace win32 {
32
33 class RegKey {
34 public:
35 // No key open
36 RegKey();
37
38 // Duplicate the specified existing key
39 RegKey(const HKEY k);
40 RegKey(const RegKey& k);
41
42 // Calls close() internally
43 ~RegKey();
44
45 void setHKEY(HKEY key, bool freeKey);
46 private:
47 RegKey& operator=(const RegKey& k);
48 HKEY& operator=(const HKEY& k);
49 public:
50
51 // Returns true if key was created, false if already existed
52 bool createKey(const RegKey& root, const TCHAR* name);
53
54 // Opens key if it exists, or raises an exception if not
55 void openKey(const RegKey& root, const TCHAR* name, bool readOnly=false);
56
57 // Set the (discretionary) access control list for the key
58 void setDACL(const PACL acl, bool inheritFromParent=true);
59
60 // Closes current key, if required
61 void close();
62
63 // Delete a subkey/value
64 void deleteKey(const TCHAR* name) const;
65 void deleteValue(const TCHAR* name) const;
66
67
68 // Block waiting for a registry change, OR return immediately and notify the
69 // event when there is a change, if specified
70 void awaitChange(bool watchSubTree, DWORD filter, HANDLE event=0) const;
71
72 void setExpandString(const TCHAR* valname, const TCHAR* s) const;
73 void setString(const TCHAR* valname, const TCHAR* s) const;
74 void setBinary(const TCHAR* valname, const void* data, int length) const;
75 void setInt(const TCHAR* valname, int i) const;
76 void setBool(const TCHAR* valname, bool b) const;
77
78 TCHAR* getString(const TCHAR* valname) const;
79 TCHAR* getString(const TCHAR* valname, const TCHAR* def) const;
80
81 void getBinary(const TCHAR* valname, void** data, int* length) const;
82 void getBinary(const TCHAR* valname, void** data, int* length, void* def, int deflength) const;
83
84 int getInt(const TCHAR* valname) const;
85 int getInt(const TCHAR* valname, int def) const;
86
87 bool getBool(const TCHAR* valname) const;
88 bool getBool(const TCHAR* valname, bool def) const;
89
90 TCHAR* getRepresentation(const TCHAR* valname) const;
91
92 bool isValue(const TCHAR* valname) const;
93
94 // Get the name of value/key number "i"
95 // If there are fewer than "i" values then return 0
96 // NAME IS OWNED BY RegKey OBJECT!
97 const TCHAR* getValueName(int i);
98 const TCHAR* getKeyName(int i);
99
100 operator HKEY() const;
101 protected:
102 HKEY key;
103 bool freeKey;
104 TCharArray valueName;
105 DWORD valueNameBufLen;
106 };
107
108 };
109
110};
111
112#endif // __RFB_WIN32_REG_CONFIG_H__