ReactOS  0.4.14-dev-57-g333b8f1
RegistryTree.h
Go to the documentation of this file.
1 //
2 // RegistryTree.h: interface for the CRegistryTree class.
3 //
5 
6 #if !defined(REGISTRYTREE_H__239A6461_70F2_11D3_9085_204C4F4F5020__INCLUDED_)
7 #define REGISTRYTREE_H__239A6461_70F2_11D3_9085_204C4F4F5020__INCLUDED_
8 
9 #include "RegistryKey.h"
10 
11 // Max size of error description.
12 #define ERROR_MSG_BUFFER_SIZE 1024
13 
15 {
16 public:
17  // Constructor
18  //
19  // Parameters:
20  // nMaxPathSize - size in characters of longest path including terminating NULL char
21  CRegistryTree();
22 
23  // Destructor
24  virtual ~CRegistryTree();
25 
26  // Call this function after fail of this class method.
27  //
28  // Return value:
29  // Pointer to buffer containing description of last error.
30  // return value is valid until next method of this class is called.
32 
33  // Call this function to get string representation (path) of current key.
34  //
35  // Return value:
36  // Pointer to buffer containing current key path. The pointer is valid until next call to this objet method.
37  const TCHAR * GetCurrentPath() const;
38 
39  // Call this function to check if current key is the root key.
40  //
41  // Return value:
42  // FALSE - current key is not the root key.
43  // TRUE - current key is the root key.
45 
46  // Call this function to change the current key.
47  //
48  // Parameters:
49  // pchRelativePath - relative path to target key.
50  //
51  // Return value:
52  // TRUE - current key changed successfully.
53  // FALSE - failed to change current key. Call GetLastErrorDescription() to get error description.
54  BOOL ChangeCurrentKey(const TCHAR *pchRelativePath);
55 
56  // Call this function to obtain key at relative path and opened with desired access.
57  //
58  // Parametes:
59  // pchRelativePath - path to key to be opened.
60  // DesiredAccess - desired access to key.
61  // rKey - reference to variable that receives pointer to key. Caller must free object with delete operator, when object is not longer needed.
62  //
63  // Return value:
64  // TRUE - key opened successfully.
65  // FALSE - failed to open desired key path size. Call GetLastErrorDescription() to get error description.
66  BOOL GetKey(const TCHAR *pchRelativePath, REGSAM DesiredAccess, CRegistryKey& rKey);
67 
68  // Call this function to delete key subkeys.
69  //
70  // Parameters:
71  // pszKeyPattern - pattern to specifying which subkeys to delete.
72  // pszPath - path to key which subkeys will be deleted.
73  // blnRecursive - if FALSE and particular subkey has subkeys, it will not be deleted.
74  //
75  // Return value:
76  // TRUE - key opened successfully.
77  // FALSE - error. Call GetLastErrorDescription() to get error description.
78  BOOL DeleteSubkeys(const TCHAR *pszKeyPattern, const TCHAR *pszPath, BOOL blnRecursive = FALSE);
79 
80  BOOL NewKey(const TCHAR *pszKeyName, const TCHAR *pszPath, BOOL blnVolatile = FALSE);
81 
82  BOOL SetMachineName(LPCTSTR pszMachineName);
83 
84 // Internal methods
85 private:
87 
88  // returns description of error value returned by RegXXXX functions in advapi32.
89  const TCHAR *GetErrorDescription(LONG nError);
90 
91  void SetError(LONG nError);
92  void SetError(const TCHAR *pszFormat, ...);
93  void SetErrorCommandNAOnRoot(const TCHAR *pszCommand);
94  void SetInternalError();
95  void AddErrorDescription(const TCHAR *pszFormat, ...);
96 
98  BOOL InternalGetSubkey(const TCHAR *pszSubkeyName, REGSAM DesiredAccess, CRegistryKey& rKey);
99  void GotoRoot();
100  BOOL DeleteSubkeys(CRegistryKey& rKey, const TCHAR *pszKeyPattern, BOOL blnRecursive);
101 
102 private:
103  class CNode
104  {
105  public:
108  } m_Root;
109 
110  CNode *m_pCurrentKey; // The current key.
111  TCHAR m_ErrorMsg[ERROR_MSG_BUFFER_SIZE+1]; // Last error description buffer.
112  LPTSTR m_pszMachineName; // Pointer to buffer containing machine name with leading backslashes. NULL if local.
113 };
114 
115 #endif // !defined(REGISTRYTREE_H__239A6461_70F2_11D3_9085_204C4F4F5020__INCLUDED_)
CNode * m_pCurrentKey
Definition: RegistryTree.h:110
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
BOOL SetMachineName(LPCTSTR pszMachineName)
class CRegistryTree::CNode m_Root
const TCHAR * GetCurrentPath() const
void SetError(LONG nError)
CHAR * LPTSTR
Definition: xmlstorage.h:192
BOOL ChangeCurrentKey(const TCHAR *pchRelativePath)
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL GetKey(const TCHAR *pchRelativePath, REGSAM DesiredAccess, CRegistryKey &rKey)
long LONG
Definition: pedump.c:60
BOOL InternalGetSubkey(const TCHAR *pszSubkeyName, REGSAM DesiredAccess, CRegistryKey &rKey)
BOOL IsCurrentRoot()
char TCHAR
Definition: xmlstorage.h:189
LPTSTR m_pszMachineName
Definition: RegistryTree.h:112
CRegistryTree Tree
void SetInternalError()
const TCHAR * GetLastErrorDescription()
BOOL InternalChangeCurrentKey(const TCHAR *pszSubkeyName, REGSAM DesiredAccess)
void SetErrorCommandNAOnRoot(const TCHAR *pszCommand)
void AddErrorDescription(const TCHAR *pszFormat,...)
const TCHAR * GetErrorDescription(LONG nError)
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define ERROR_MSG_BUFFER_SIZE
Definition: RegistryTree.h:12
ACCESS_MASK REGSAM
Definition: winreg.h:69
BOOL NewKey(const TCHAR *pszKeyName, const TCHAR *pszPath, BOOL blnVolatile=FALSE)
BOOL DeleteSubkeys(const TCHAR *pszKeyPattern, const TCHAR *pszPath, BOOL blnRecursive=FALSE)
TCHAR m_ErrorMsg[ERROR_MSG_BUFFER_SIZE+1]
Definition: RegistryTree.h:111
virtual ~CRegistryTree()
CRegistryKey m_Key
Definition: RegistryTree.h:107