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