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.

157 lines
4.8 KiB

  1. #ifndef _REGISTRY_H_
  2. #define _CRegKey_REGISTRY_defined_can_not_include_ATLBASE_H_/* new #def name */
  3. #define _REGISTRY_H_ /* old #def name */
  4. //----------------------------------------------------------------
  5. // we need the new explicit name since TW_Util.* needs to know if
  6. // its defined in the iis\ui\setup\osrc directory that also defines
  7. // a CRegKey class. If so it will have trouble including a std
  8. // windows file called <AtlBase.h>
  9. // It keys off of: _CRegKey_REGISTRY_nonATLBASE_H_
  10. //----------------------------------------------------------------
  11. /****************************************************************************
  12. REGISTRY.H
  13. ****************************************************************************/
  14. // Forward declarations
  15. class CRegKey ;
  16. class CRegValueIter ;
  17. class CRegKeyIter ;
  18. // Maximum size of a Registry class name
  19. #define CREGKEY_MAX_CLASS_NAME MAX_PATH
  20. // Wrapper for a Registry key handle.
  21. class CRegKey : public CObject
  22. {
  23. protected:
  24. HKEY m_hKey ;
  25. DWORD m_dwDisposition ;
  26. // Prepare to read a value by finding the value's size.
  27. LONG PrepareValue ( LPCTSTR pchValueName,
  28. DWORD * pdwType,
  29. DWORD * pcbSize,
  30. BYTE ** ppbData ) ;
  31. // Convert a CStringList to the REG_MULTI_SZ format
  32. static LONG FlattenValue ( CStringList & strList,
  33. DWORD * pcbSize,
  34. BYTE ** ppbData ) ;
  35. // Convert a CByteArray to a REG_BINARY block
  36. static LONG FlattenValue ( CByteArray & abData,
  37. DWORD * pcbSize,
  38. BYTE ** ppbData ) ;
  39. public:
  40. // Key information return structure
  41. typedef struct
  42. {
  43. TCHAR chBuff [CREGKEY_MAX_CLASS_NAME] ;
  44. DWORD dwClassNameSize,
  45. dwNumSubKeys,
  46. dwMaxSubKey,
  47. dwMaxClass,
  48. dwMaxValues,
  49. dwMaxValueName,
  50. dwMaxValueData,
  51. dwSecDesc ;
  52. FILETIME ftKey ;
  53. } CREGKEY_KEY_INFO ;
  54. // Standard constructor for an existing key
  55. CRegKey ( HKEY hKeyBase,
  56. LPCTSTR pchSubKey = NULL,
  57. REGSAM regSam = KEY_ALL_ACCESS ) ;
  58. // Constructor creating a new key.
  59. CRegKey ( LPCTSTR lpSubKey,
  60. HKEY hKeyBase,
  61. LPCTSTR lpValueName = NULL,
  62. DWORD dwType = 0,
  63. LPBYTE lpValueData = NULL,
  64. DWORD cbValueData = 0);
  65. ~ CRegKey () ;
  66. // Allow a CRegKey to be used anywhere an HKEY is required.
  67. operator HKEY ()
  68. { return m_hKey ; }
  69. // Fill a key information structure
  70. LONG QueryKeyInfo ( CREGKEY_KEY_INFO * pRegKeyInfo ) ;
  71. // Overloaded value query members; each returns ERROR_INVALID_PARAMETER
  72. // if data exists but not in correct form to deliver into result object.
  73. LONG QueryValue ( LPCTSTR pchValueName, CString & strResult ) ;
  74. LONG QueryValue ( LPCTSTR pchValueName, CStringList & strList ) ;
  75. LONG QueryValue ( LPCTSTR pchValueName, DWORD & dwResult ) ;
  76. LONG QueryValue ( LPCTSTR pchValueName, CByteArray & abResult ) ;
  77. LONG QueryValue ( LPCTSTR pchValueName, void * pvResult, DWORD cbSize );
  78. // Overloaded value setting members.
  79. LONG SetValue ( LPCTSTR pchValueName, LPCTSTR szResult, BOOL fExpand = FALSE ) ;
  80. LONG SetValue ( LPCTSTR pchValueName, CStringList & strList ) ;
  81. LONG SetValue ( LPCTSTR pchValueName, DWORD dwResult ) ;
  82. LONG SetValue ( LPCTSTR pchValueName, CByteArray & abResult ) ;
  83. LONG SetValue ( LPCTSTR pchValueName, void * pvResult, DWORD cbSize );
  84. LONG DeleteValue( LPCTSTR pchKeyName );
  85. LONG DeleteTree( LPCTSTR pchKeyName );
  86. int m_iDisplayWarnings;
  87. };
  88. // Iterate the values of a key, return the name and type
  89. // of each.
  90. class CRegValueIter : public CObject
  91. {
  92. protected:
  93. CRegKey & m_rk_iter ;
  94. DWORD m_dw_index ;
  95. TCHAR * m_p_buffer ;
  96. DWORD m_cb_buffer ;
  97. public:
  98. CRegValueIter ( CRegKey & regKey ) ;
  99. ~ CRegValueIter () ;
  100. // Get the name (and optional last write time) of the next key.
  101. LONG Next ( CString * pstrName, DWORD * pdwType ) ;
  102. LONG Next ( CString * pstrName, CString * pstrValue );
  103. // decrement the m_dw_index to account for deleted keys
  104. void Decrement( DWORD delta = 1 ) {m_dw_index -= delta;}
  105. // Reset the iterator
  106. void Reset ()
  107. { m_dw_index = 0 ; }
  108. };
  109. // Iterate the sub-key names of a key.
  110. class CRegKeyIter : public CObject
  111. {
  112. protected:
  113. CRegKey & m_rk_iter ;
  114. DWORD m_dw_index ;
  115. TCHAR * m_p_buffer ;
  116. DWORD m_cb_buffer ;
  117. public:
  118. CRegKeyIter ( CRegKey & regKey ) ;
  119. ~ CRegKeyIter () ;
  120. // Get the name (and optional last write time) of the next key.
  121. LONG Next ( CString * pstrName, CTime * pTime = NULL ) ;
  122. // Reset the iterator
  123. void Reset ()
  124. { m_dw_index = 0 ; }
  125. };
  126. #endif // _REGISTRY_H_