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.

148 lines
3.5 KiB

  1. #ifndef _INC_DSKQUOTA_REGISTRY_H
  2. #define _INC_DSKQUOTA_REGISTRY_H
  3. #ifndef _WINDOWS_
  4. # include <windows.h>
  5. #endif
  6. #ifndef _INC_DSKQUOTA_STRCLASS_H
  7. # include "strclass.h"
  8. #endif
  9. #ifndef _INC_DSKQUOTA_CARRAY_H
  10. # include "carray.h"
  11. #endif
  12. //
  13. // Represents a single registry key. Provides basic functions for
  14. // opening and closing the key as well as setting and querying for
  15. // values in that key. Closure of the key handle is ensured through
  16. // the destructor.
  17. //
  18. class RegKey
  19. {
  20. public:
  21. RegKey(void);
  22. RegKey(HKEY hkeyRoot, LPCTSTR pszSubKey);
  23. virtual ~RegKey(void);
  24. operator HKEY(void) const
  25. { return m_hkey; }
  26. HKEY GetHandle(void) const
  27. { return m_hkey; }
  28. HRESULT Open(REGSAM samDesired, bool bCreate = false) const;
  29. void Attach(HKEY hkey);
  30. void Detach(void);
  31. void Close(void) const;
  32. int GetValueBufferSize(
  33. LPCTSTR pszValueName) const;
  34. bool IsOpen(void) const
  35. { return NULL != m_hkey; }
  36. HRESULT WatchForChange(DWORD dwChangeFilter, bool bWatchSubtree = false);
  37. HRESULT WaitForChange(DWORD dwChangeFilter, bool bWatchSubtree = false);
  38. //
  39. // Retrieve REG_DWORD
  40. //
  41. HRESULT GetValue(
  42. LPCTSTR pszValueName,
  43. DWORD *pdwDataOut) const;
  44. //
  45. // Retrieve REG_BINARY
  46. //
  47. HRESULT GetValue(
  48. LPCTSTR pszValueName,
  49. LPBYTE pbDataOut,
  50. int cbDataOut) const;
  51. //
  52. // Retrieve REG_SZ
  53. //
  54. HRESULT GetValue(
  55. LPCTSTR pszValueName,
  56. CString *pstrDataOut) const;
  57. //
  58. // Retrieve REG_MULTI_SZ
  59. //
  60. HRESULT GetValue(
  61. LPCTSTR pszValueName,
  62. CArray<CString> *prgstrOut) const;
  63. //
  64. // Set REG_DWORD
  65. //
  66. HRESULT SetValue(
  67. LPCTSTR pszValueName,
  68. DWORD dwData);
  69. //
  70. // Set REG_BINARY
  71. //
  72. HRESULT SetValue(
  73. LPCTSTR pszValueName,
  74. const LPBYTE pbData,
  75. int cbData);
  76. //
  77. // Set REG_SZ
  78. //
  79. HRESULT SetValue(
  80. LPCTSTR pszValueName,
  81. LPCTSTR pszData);
  82. //
  83. // Set REG_MULTI_SZ
  84. //
  85. HRESULT SetValue(
  86. LPCTSTR pszValueName,
  87. const CArray<CString>& rgstrData);
  88. protected:
  89. virtual void OnChange(HKEY hkey);
  90. private:
  91. HKEY m_hkeyRoot;
  92. mutable HKEY m_hkey;
  93. HANDLE m_hChangeEvent;
  94. DWORD m_dwChangeFilter;
  95. CString m_strSubKey;
  96. bool m_bWatchSubtree;
  97. HRESULT SetValue(
  98. LPCTSTR pszValueName,
  99. DWORD dwValueType,
  100. const LPBYTE pbData,
  101. int cbData);
  102. HRESULT GetValue(
  103. LPCTSTR pszValueName,
  104. DWORD dwTypeExpected,
  105. LPBYTE pbData,
  106. int cbData) const;
  107. LPTSTR CreateDoubleNulTermList(
  108. const CArray<CString>& rgstrSrc) const;
  109. static DWORD NotifyWaitThreadProc(LPVOID pvParam);
  110. //
  111. // Prevent copy.
  112. //
  113. RegKey(const RegKey& rhs);
  114. RegKey& operator = (const RegKey& rhs);
  115. };
  116. #if DBG
  117. class RegKeyChg : public RegKey
  118. {
  119. public:
  120. RegKeyChg(HKEY hkeyRoot, LPCTSTR pszSubKey);
  121. ~RegKeyChg(void);
  122. protected:
  123. virtual void OnChange(HKEY hkey);
  124. };
  125. #endif // #if DBG
  126. #endif // _INC_DSKQUOTA_REGISTRY_H