1 // RegistryKey.h: interface for the CRegistryKey class.
3 //////////////////////////////////////////////////////////////////////
5 #if !defined(REGISTRYKEY_H__FEF419ED_6EB6_11D3_907D_204C4F4F5020__INCLUDED_)
6 #define REGISTRYKEY_H__FEF419ED_6EB6_11D3_907D_204C4F4F5020__INCLUDED_
11 // Constructor. Call InitXXX methods to make real construct.
14 // Call this key to init root key.
17 // pszMachineName - pointer to buffer containing machine name. NULL means local machine.
22 HRESULT
InitRoot(const TCHAR
*pszMachineName
= NULL
);
24 // Call this method to init normal key.
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.
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.
40 HRESULT
Init(HKEY hKey
, const TCHAR
*pszPath
, const TCHAR
*pszKeyName
, REGSAM CurrentAccess
);
42 // Call this method to uninitialize the object.
50 virtual ~CRegistryKey();
52 // Call ths function to check if handle to key is handle to hive root.
55 // hKey - handle to check.
58 // TRUE - hKey is handle to hive root.
59 // FALSE - hKey is not handle to hive root.
60 static BOOL
IsHive(HKEY hKey
);
62 // Call this method to get name of key represented by this object.
65 // Pointer to buffer containing key name. Return value is valid until next call to this object method.
66 const TCHAR
* GetKeyName();
70 // Call this method to open existing subkey of this key.
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.
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
);
82 // Call this method to open existing subkey of this key.
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.
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
);
94 // Call this method to get the length in TCHARs of longest subkey name, including terminating null.
97 // rdwMaxSubkeyNameLength, reference to variable that receives size in TCHARs of longest subkey name.
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
);
104 // Call this method to init subkey enumeration. I.e. before first call to GetSubkeyName()
107 // pchSubkeyNameBuffer - pointer to buffer receiving subkey name.
108 // dwBufferSize - size, in TCHARs of buffer pointed by pchSubkeyNameBuffer.
110 void InitSubkeyEnumeration(TCHAR
*pchSubkeyNameBuffer
, DWORD dwBufferSize
);
112 // Call this method to get next subkey name. Name is stored in buffer specified in call to InitSubKeyEnumeration.
115 // pdwActualSize - optional pointer to variable receiving actual size, in TCHARs, of key name. The count returned does not include the terminating null.
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
);
123 // Call this method to get count of subkeys.
126 // rdwSubkeyCount - reference to variable that receives subkey count.
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
);
133 // Call this method to get the length in TCHARs of longest value name, including terminating null.
136 // rdwMaxValueNameBufferSize receives the length, in TCHARs, of the key's longest value name.
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
);
143 // Call this method to get the size of larges value data.
146 // rdwMaxValueDataBufferSize receives the length, in bytes, of the longest data component among the key's values.
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
);
153 // Call this method to init subkey enumeration. I.e. before first call to GetSubkeyName()
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
,
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.
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.
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
);
179 // Call this method to get count of values.
182 // rdwValueCount - reference to variable that receives value count.
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
);
189 // Call this method to get data and/or type of default value.
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.
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
);
202 // Call this function to get text representation of value type.
205 // dwType - type to get text representation from.
208 // text representation od value type.
209 static const TCHAR
* GetValueTypeName(DWORD dwType
);
211 DWORD
GetValue(TCHAR
*pchValueName
, DWORD
*pdwType
, LPBYTE lpValueDataBuffer
, DWORD
*pdwValueDataSize
);
213 // Call this method to create subkey of this key.
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.
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
);
227 LONG
GetLastWriteTime(SYSTEMTIME
& st
);
228 const TCHAR
* GetLastWriteTime();
230 LONG
DeleteValue(const TCHAR
*pszValueName
);
231 LONG
DeleteSubkey(const TCHAR
*pszPatternSubkeyName
);
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
);
238 operator HKEY(){return m_hKey
;};
240 DWORD m_dwCurrentSubKeyIndex
;
241 TCHAR
*m_pchSubkeyNameBuffer
;
242 DWORD m_dwSubkeyNameBufferSize
;
244 DWORD m_dwCurrentValueIndex
;
245 TCHAR
*m_pszValueNameBuffer
;
246 DWORD m_dwValueNameBufferSize
;
247 BYTE
*m_pbValueDataBuffer
;
248 DWORD m_dwValueDataBufferSize
;
253 TCHAR
*m_pszMachineName
;
254 REGSAM m_CurrentAccess
;
257 #endif // !defined(REGISTRYKEY_H__FEF419ED_6EB6_11D3_907D_204C4F4F5020__INCLUDED_)