no message
[reactos.git] / rosapps / sysutils / regexpl / RegistryKey.h
1 // RegistryKey.h: interface for the CRegistryKey class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #if !defined(REGISTRYKEY_H__FEF419ED_6EB6_11D3_907D_204C4F4F5020__INCLUDED_)
6 #define REGISTRYKEY_H__FEF419ED_6EB6_11D3_907D_204C4F4F5020__INCLUDED_
7
8 class CRegistryKey
9 {
10 public:
11 // Constructor. Call InitXXX methods to make real construct.
12 CRegistryKey();
13
14 // Call this key to init root key.
15 //
16 // Parameters:
17 // pszMachineName - pointer to buffer containing machine name. NULL means local machine.
18 //
19 // Return value:
20 // S_OK - All ok.
21 // E_XXX - Error.
22 HRESULT InitRoot(const TCHAR *pszMachineName = NULL);
23
24 // Call this method to init normal key.
25 //
26 // Parameters:
27 // hKey - handle to opened key.
28 // pszPath - optional path string. NULL if pszKeyName is the needed name.
29 // pszKeyName - pointer to buffer conatining name of key.
30 // CurrentAccess - Access of hKey.
31 //
32 // Remarks:
33 // Constructs key object from handle.
34 // The constructed object hold the handle and closes it on destruction. Do not close handle outside.
35 // If pszPath is not NULL, it is concatenated with pszKeyName.
36 //
37 // Return value:
38 // S_OK - All ok.
39 // E_XXX - Error.
40 HRESULT Init(HKEY hKey, const TCHAR *pszPath, const TCHAR *pszKeyName, REGSAM CurrentAccess);
41
42 // Call this method to uninitialize the object.
43 //
44 // Return value:
45 // S_OK - All ok.
46 // E_XXX - Error.
47 HRESULT Uninit();
48
49 // Destructor
50 virtual ~CRegistryKey();
51
52 // Call ths function to check if handle to key is handle to hive root.
53 //
54 // Parameters:
55 // hKey - handle to check.
56 //
57 // Return value:
58 // TRUE - hKey is handle to hive root.
59 // FALSE - hKey is not handle to hive root.
60 static BOOL IsHive(HKEY hKey);
61
62 // Call this method to get name of key represented by this object.
63 //
64 // Return value:
65 // Pointer to buffer containing key name. Return value is valid until next call to this object method.
66 const TCHAR * GetKeyName();
67
68 BOOL IsRoot();
69
70 // Call this method to open existing subkey of this key.
71 //
72 // Parameters:
73 // samDesired - deisred access.
74 // pszSubkeyName - pointer to bufer containing name of key to open.
75 // rhKey - reference to variable that receives handle of opened key. If method fails, variable value is unchanged.
76 //
77 // Return value:
78 // If the method succeeds, the return value is ERROR_SUCCESS.
79 // If the method fails, the return value is a nonzero error code defined in winerror.h.
80 LONG OpenSubkey(REGSAM samDesired, const TCHAR *pszSubkeyName, HKEY &rhKey);
81
82 // Call this method to open existing subkey of this key.
83 //
84 // Parameters:
85 // samDesired - deisred access.
86 // pszSubkeyName - pointer to bufer containing name of key to open.
87 // rKey - reference to CRegistryKey object. If method succeeds, rKey is initialized with newly opened key.
88 //
89 // Return value:
90 // If the method succeeds, the return value is ERROR_SUCCESS.
91 // If the method fails, the return value is a nonzero error code defined in winerror.h.
92 LONG OpenSubkey(REGSAM samDesired, const TCHAR *pszSubkeyName, CRegistryKey &rKey);
93
94 // Call this method to get the length in TCHARs of longest subkey name, including terminating null.
95 //
96 // Parameters:
97 // rdwMaxSubkeyNameLength, reference to variable that receives size in TCHARs of longest subkey name.
98 //
99 // Return value.
100 // If the method succeeds, the return value is ERROR_SUCCESS.
101 // If the method fails, the return value is a nonzero error code defined in winerror.h.
102 LONG GetSubkeyNameMaxLength(DWORD &rdwMaxSubkeyNameLength);
103
104 // Call this method to init subkey enumeration. I.e. before first call to GetSubkeyName()
105 //
106 // Parameters:
107 // pchSubkeyNameBuffer - pointer to buffer receiving subkey name.
108 // dwBufferSize - size, in TCHARs of buffer pointed by pchSubkeyNameBuffer.
109 //
110 void InitSubkeyEnumeration(TCHAR *pchSubkeyNameBuffer, DWORD dwBufferSize);
111
112 // Call this method to get next subkey name. Name is stored in buffer specified in call to InitSubKeyEnumeration.
113 //
114 // Parameters:
115 // pdwActualSize - optional pointer to variable receiving actual size, in TCHARs, of key name. The count returned does not include the terminating null.
116 //
117 // Return value:
118 // If the method succeeds, the return value is ERROR_SUCCESS.
119 // If the method fails, the return value is a nonzero error code defined in winerror.h.
120 // If no more items available, return error is ERROR_NO_MORE_ITEMS.
121 LONG GetNextSubkeyName(DWORD *pdwActualSize = NULL);
122
123 // Call this method to get count of subkeys.
124 //
125 // Parameters:
126 // rdwSubkeyCount - reference to variable that receives subkey count.
127 //
128 // Return value:
129 // If the method succeeds, the return value is ERROR_SUCCESS.
130 // If the method fails, the return value is a nonzero error code defined in winerror.h.
131 LONG GetSubkeyCount(DWORD &rdwSubkeyCount);
132
133 // Call this method to get the length in TCHARs of longest value name, including terminating null.
134 //
135 // Parameters:
136 // rdwMaxValueNameBufferSize receives the length, in TCHARs, of the key's longest value name.
137 //
138 // Return value:
139 // If the method succeeds, the return value is ERROR_SUCCESS.
140 // If the method fails, the return value is a nonzero error code defined in winerror.h.
141 LONG GetMaxValueNameLength(DWORD& rdwMaxValueNameBufferSize);
142
143 // Call this method to get the size of larges value data.
144 //
145 // Parameters:
146 // rdwMaxValueDataBufferSize receives the length, in bytes, of the longest data component among the key's values.
147 //
148 // Return value:
149 // If the method succeeds, the return value is ERROR_SUCCESS.
150 // If the method fails, the return value is a nonzero error code defined in winerror.h.
151 LONG GetMaxValueDataSize(DWORD& rdwMaxValueDataBufferSize);
152
153 // Call this method to init subkey enumeration. I.e. before first call to GetSubkeyName()
154 //
155 // Parameters:
156 // pszValueNameBuffer - pointer to buffer receiving value name. If NULL, value name in not received upon iteration.
157 // dwValueNameBufferSize - size, in TCHARs of buffer pointed by pszValueNameBuffer. If pszValueNameBuffer is NULL, parameter is ignored.
158 // pbValueDataBuffer - pointer to buffer receiving value name. If NULL, value data is not received upon iteration.
159 // dwValueDataBufferSize - size, in bytes of buffer pointed by pbValueDataBuffer. If pbValueDataBuffer is NULL, parameter is ignored.
160 // pdwType - pointer to variable receiving value type. If NULL, value type is not received upon iteration.
161 void InitValueEnumeration(TCHAR *pszValueNameBuffer,
162 DWORD dwValueNameBufferSize,
163 BYTE *pbValueDataBuffer,
164 DWORD dwValueDataBufferSize,
165 DWORD *pdwType);
166
167 // Call this method to get next value name/data/type. Name/data/type is/are stored in buffer(s) specified in call to InitValueEnumeration.
168 //
169 // Parameters:
170 // pdwNameActualSize - optional pointer to variable receiving actual size, in TCHARs, of value name. The count returned includes the terminating null.
171 // pdwActualSize - optional pointer to variable receiving actual size, in bytes, of key name. The count returned does not include the terminating null.
172 //
173 // Return value:
174 // If the method succeeds, the return value is ERROR_SUCCESS.
175 // If the method fails, the return value is a nonzero error code defined in winerror.h.
176 // If no more items available, return error is ERROR_NO_MORE_ITEMS.
177 LONG GetNextValue(DWORD *pdwNameActualSize = NULL, DWORD *pdwDataActualSize = NULL);
178
179 // Call this method to get count of values.
180 //
181 // Parameters:
182 // rdwValueCount - reference to variable that receives value count.
183 //
184 // Return value:
185 // If the method succeeds, the return value is ERROR_SUCCESS.
186 // If the method fails, the return value is a nonzero error code defined in winerror.h.
187 LONG GetValueCount(DWORD& rdwValueCount);
188
189 // Call this method to get data and/or type of default value.
190 //
191 // Parameters:
192 // pdwType - optional pointer to variable receiving default value type. NULL if not requred.
193 // pbValueDataBuffer - optional pointer to buffer receiving default value data. NULL if not requred.
194 // dwValueDataBufferSize - size of buffer pointer by pbValueDataBuffer. Ignored if pbValueDataBuffer is NULL.
195 // pdwValueDataActualSize - optional pointer to variable receiving size, in bytes, of data stored into buffer. If pbValueDataBuffer is NULL, returned value is size of default value data, in bytes.
196 //
197 // Return value:
198 // If the method succeeds, the return value is ERROR_SUCCESS.
199 // If the method fails, the return value is a nonzero error code defined in winerror.h.
200 LONG GetDefaultValue(DWORD *pdwType, BYTE *pbValueDataBuffer, DWORD dwValueDataBufferSize, DWORD *pdwValueDataActualSize);
201
202 // Call this function to get text representation of value type.
203 //
204 // Parameters:
205 // dwType - type to get text representation from.
206 //
207 // Return value:
208 // text representation od value type.
209 static const TCHAR * GetValueTypeName(DWORD dwType);
210
211 DWORD GetValue(TCHAR *pchValueName, DWORD *pdwType, LPBYTE lpValueDataBuffer, DWORD *pdwValueDataSize);
212
213 // Call this method to create subkey of this key.
214 //
215 // Parameters:
216 // samDesired - deisred access.
217 // pszKeyName - pointer to bufer containing name of key to create.
218 // rhKey - reference to variable that receives handle of opened key. If method fails, variable value is unchanged.
219 // pblnOpened - optional pointer to variable that receives create/open status. If subkey is opened value is TRUE. If key is created value is FALSE.
220 // blnVolatile - opitional parameter specifining if created key is volatile.
221 //
222 // Return value:
223 // If the method succeeds, the return value is ERROR_SUCCESS.
224 // If the method fails, the return value is a nonzero error code defined in winerror.h.
225 LONG CreateSubkey(REGSAM samDesired, const TCHAR *pszKeyName, HKEY &rhKey, BOOL *pblnOpened = NULL, BOOL blnVolatile = FALSE);
226
227 LONG GetLastWriteTime(SYSTEMTIME& st);
228 const TCHAR * GetLastWriteTime();
229
230 LONG DeleteValue(const TCHAR *pszValueName);
231 LONG DeleteSubkey(const TCHAR *pszPatternSubkeyName);
232
233 LONG SetValue(LPCTSTR pszValueName, DWORD dwType, BYTE *lpData, DWORD dwDataSize);
234 TCHAR * GetSubKeyNameByIndex(DWORD dwIndex);
235 LONG GetSecurityDescriptor(SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, LPDWORD lpcbSecurityDescriptor);
236 LONG GetSecurityDescriptorLength(DWORD *pdwSecurityDescriptor);
237 BOOL IsPredefined();
238 operator HKEY(){return m_hKey;};
239 private:
240 DWORD m_dwCurrentSubKeyIndex;
241 TCHAR *m_pchSubkeyNameBuffer;
242 DWORD m_dwSubkeyNameBufferSize;
243
244 DWORD m_dwCurrentValueIndex;
245 TCHAR *m_pszValueNameBuffer;
246 DWORD m_dwValueNameBufferSize;
247 BYTE *m_pbValueDataBuffer;
248 DWORD m_dwValueDataBufferSize;
249 DWORD *m_pdwType;
250
251 HKEY m_hKey;
252 TCHAR *m_pszKeyName;
253 TCHAR *m_pszMachineName;
254 REGSAM m_CurrentAccess;
255 };
256
257 #endif // !defined(REGISTRYKEY_H__FEF419ED_6EB6_11D3_907D_204C4F4F5020__INCLUDED_)