Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
5.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SIMREG.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/12/1998
  12. *
  13. * DESCRIPTION: Simple registry access class
  14. *
  15. *******************************************************************************/
  16. #ifndef __SIMREG_H_INCLUDED
  17. #define __SIMREG_H_INCLUDED
  18. #include <windows.h>
  19. #include "simstr.h"
  20. class CSimpleReg
  21. {
  22. private:
  23. CSimpleString m_strKeyName;
  24. HKEY m_hRootKey;
  25. HKEY m_hKey;
  26. bool m_bCreate;
  27. LPSECURITY_ATTRIBUTES m_lpsaSecurityAttributes;
  28. REGSAM m_samDesiredAccess;
  29. public:
  30. // Process current node-->recurse
  31. // or
  32. // recurse-->Process current node
  33. enum
  34. {
  35. PreOrder=0,
  36. PostOrder=1
  37. };
  38. // structure passed to key enumeration proc
  39. struct CKeyEnumInfo
  40. {
  41. CSimpleString strName;
  42. HKEY hkRoot;
  43. int nLevel;
  44. LPARAM lParam;
  45. };
  46. // structure passed to value enumeration proc
  47. class CValueEnumInfo
  48. {
  49. private:
  50. // No implementation
  51. CValueEnumInfo(void);
  52. CValueEnumInfo &operator=( const CValueEnumInfo & );
  53. CValueEnumInfo( const CValueEnumInfo & );
  54. public:
  55. CValueEnumInfo( CSimpleReg &_reg, const CSimpleString &_strName, DWORD _nType, DWORD _nSize, LPARAM _lParam )
  56. : reg(_reg), strName(_strName), nType(_nType), nSize(_nSize), lParam(_lParam)
  57. {
  58. }
  59. CSimpleReg &reg;
  60. CSimpleString strName;
  61. DWORD nType;
  62. DWORD nSize;
  63. LPARAM lParam;
  64. };
  65. // Enumeration procs
  66. typedef bool (*SimRegKeyEnumProc)( CKeyEnumInfo &enumInfo );
  67. typedef bool (*SimRegValueEnumProc)( CValueEnumInfo &enumInfo );
  68. // Constructors, destructor and assignment operator
  69. CSimpleReg( HKEY hkRoot, const CSimpleString &strSubKey, bool bCreate=false, REGSAM samDesired=KEY_ALL_ACCESS, LPSECURITY_ATTRIBUTES lpsa=NULL );
  70. CSimpleReg(void);
  71. CSimpleReg(const CSimpleReg &other);
  72. virtual ~CSimpleReg(void);
  73. CSimpleReg &operator=(const CSimpleReg &other );
  74. // Open and close
  75. bool Open(void);
  76. bool Close(void);
  77. bool Flush(void);
  78. // Key and value information
  79. DWORD Size( const CSimpleString &key ) const;
  80. DWORD Type( const CSimpleString &key ) const;
  81. DWORD SubKeyCount(void) const;
  82. // Query functions
  83. CSimpleString Query( const CSimpleString &strValueName, const CSimpleString &strDef ) const;
  84. LPTSTR Query( const CSimpleString &strValueName, const CSimpleString &strDef, LPTSTR pszBuffer, DWORD nLen ) const;
  85. DWORD Query( const CSimpleString &strValueName, DWORD nDef ) const;
  86. DWORD QueryBin( const CSimpleString &strValueName, PBYTE pData, DWORD nMaxLen ) const;
  87. // Set functions
  88. bool Set( const CSimpleString &strValueName, const CSimpleString &strValue, DWORD nType=REG_SZ ) const;
  89. bool Set( const CSimpleString &strValueName, DWORD nValue ) const;
  90. bool SetBin( const CSimpleString &strValueName, const PBYTE pValue, DWORD nLen, DWORD dwType = REG_BINARY ) const;
  91. // Delete a value
  92. bool Delete( const CSimpleString &strValue );
  93. // Some static helpers
  94. static bool IsStringValue( DWORD nType );
  95. static HKEY GetHkeyFromName( const CSimpleString &strName );
  96. static bool Delete( HKEY hkRoot, const CSimpleString &stKeyName );
  97. static bool DeleteRecursively( HKEY hkRoot, const CSimpleString &strKeyName );
  98. // Inline accessor functions
  99. const LPSECURITY_ATTRIBUTES GetSecurityAttributes(void) const
  100. {
  101. return(m_lpsaSecurityAttributes);
  102. }
  103. CSimpleString GetSubKeyName(void) const
  104. {
  105. return(m_strKeyName);
  106. }
  107. bool GetCreate(void) const
  108. {
  109. return(m_bCreate);
  110. }
  111. HKEY GetRootKey(void) const
  112. {
  113. return(m_hRootKey);
  114. }
  115. HKEY GetKey(void) const
  116. {
  117. return(m_hKey);
  118. }
  119. REGSAM DesiredAccess(void) const
  120. {
  121. return m_samDesiredAccess;
  122. }
  123. // Status
  124. bool OK(void) const
  125. {
  126. return(m_hRootKey && m_hKey);
  127. }
  128. operator bool(void) const
  129. {
  130. return(OK());
  131. }
  132. operator HKEY(void) const
  133. {
  134. return(GetKey());
  135. }
  136. // Enumeration and recursion
  137. bool EnumValues( SimRegValueEnumProc enumProc, LPARAM lParam = 0 );
  138. bool RecurseKeys( SimRegKeyEnumProc enumProc, LPARAM lParam = 0, int recurseOrder = CSimpleReg::PostOrder, bool bFailOnOpenError = true ) const;
  139. bool EnumKeys( SimRegKeyEnumProc enumProc, LPARAM lParam = 0, bool bFailOnOpenError = true ) const;
  140. protected:
  141. // Recursion and enumeration implementation
  142. static bool DoRecurseKeys( HKEY hkKey, const CSimpleString &root, SimRegKeyEnumProc enumProc, LPARAM lParam, int nLevel, int recurseOrder, bool bFailOnOpenError );
  143. static bool DoEnumKeys( HKEY hkKey, const CSimpleString &root, SimRegKeyEnumProc enumProc, LPARAM lParam, bool bFailOnOpenError );
  144. // Recursion proc that allows us to recursively nuke a registry tree
  145. static bool DeleteEnumKeyProc( CSimpleReg::CKeyEnumInfo &enumInfo );
  146. };
  147. #endif