Leaked source code of windows server 2003
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.

215 lines
6.6 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. fusionregenumkeys.h
  5. Abstract:
  6. ported from vsee\lib\reg\ckey.h
  7. Author:
  8. Jay Krell (JayKrell) August 2001
  9. Revision History:
  10. --*/
  11. #if !defined(FUSION_INC_REGKEY2_H_INCLUDED_) // {
  12. #define FUSION_INC_REGKEY2_H_INCLUDED_
  13. #pragma once
  14. #include "windows.h"
  15. #include "fusionbuffer.h"
  16. #include "lhport.h"
  17. namespace F
  18. {
  19. /*-----------------------------------------------------------------------------
  20. Name: CRegKey2
  21. @class
  22. This class is a "smart" wrapper for an HKEY.
  23. @hung key or hkey
  24. @owner
  25. -----------------------------------------------------------------------------*/
  26. class CRegKey2
  27. {
  28. public:
  29. // @cmember constructor
  30. __declspec(nothrow) CRegKey2() /*throw()*/;
  31. // @cmember constructor
  32. __declspec(nothrow) CRegKey2(HKEY) /*throw()*/;
  33. // @cmember destructor
  34. __declspec(nothrow) ~CRegKey2() /*throw()*/;
  35. // @cmember open
  36. void ThrOpen(HKEY hKeyParent, PCWSTR pszKeyName, REGSAM samDesired = KEY_READ) throw(CErr);
  37. // @cmember open can fail reasonably with
  38. // at least ERROR_FILE_NOT_FOUND (2),
  39. // can still throw for invalid parameters, etc.
  40. __declspec(nothrow) HRESULT HrOpen(HKEY hKeyParent, PCWSTR pszKeyName, REGSAM samDesired = KEY_READ) /*throw()*/;
  41. // @cmember return disposition
  42. DWORD Create(HKEY hKeyParent, PCWSTR pszKeyName, REGSAM samDesired = KEY_ALL_ACCESS) throw(CErr);
  43. // @cmember Delete a value from registry
  44. void ThrDeleteValue ( const F::CBaseStringBuffer& strValueName );
  45. // @cmember operator =
  46. VOID operator=(HKEY) throw(CErr);
  47. // @cmember operator HKEY
  48. operator HKEY() throw(CErr); // bitwise const, but not necessarily logically const
  49. // @cmember same as operator=
  50. void ThrAttach(HKEY) throw(CErr);
  51. __declspec(nothrow) HKEY Detach() /*throw()*/;
  52. // @cmember set value
  53. void ThrSetValue(PCWSTR pszValueName, const F::CBaseStringBuffer& strValue) throw(CErr);
  54. // @cmember set value
  55. void ThrSetValue(PCWSTR pszValueName, const DWORD& dwValue) throw(CErr);
  56. // @cmember query value
  57. void ThrQueryValue(PCWSTR pszValueName, DWORD* pdwType, BYTE* pbData, DWORD* pcbData) const throw(CErr);
  58. // @cmember query value
  59. void ThrQueryValue(PCWSTR szValueName, F::CBaseStringBuffer* pstrValue) const throw(CErr);
  60. // @cmember FUTURE
  61. //void ThrQueryValue(PCWSTR szValueName, DWORD* pdwValue) const throw(CErr);
  62. // @cmember query can fail reasonably with at least ERROR_FILE_NOT_FOUND (==2),
  63. // can still throw for invalid parameters, etc.
  64. HRESULT HrQueryValue(PCWSTR szValueName, F::CBaseStringBuffer* pstrValue) const throw(CErr);
  65. // @cmember query can fail reasonably with at least ERROR_FILE_NOT_FOUND (==2),
  66. // can still throw for invalid parameters, etc.
  67. HRESULT HrQueryValue(PCWSTR szValueName, DWORD* pdwValue) const throw(CErr);
  68. // @cmember a subset of RegQueryInfoKey
  69. // consumed by CEnumValues
  70. static void ThrQueryValuesInfo(HKEY hKey, DWORD* pcValues, DWORD* pcchMaxValueNameLength, DWORD* pcbMaxValueLength) throw(CErr);
  71. // @cmember a subset of RegQueryInfoKey
  72. // consumed by CEnumKeys
  73. static void ThrQuerySubKeysInfo(HKEY hKey, DWORD* pcSubKeys, DWORD* pcchMaxSubKeyNameLength) throw(CErr);
  74. // @cmember
  75. // intended client is CEnumKeys, so lack of F::CStringBuffer support is ok
  76. static void ThrEnumKey(HKEY hKey, DWORD dwIndex, PWSTR pszSubKeyName, DWORD* pcchSubKeyNameLength) throw(CErr);
  77. static LONG RegEnumKey(HKEY hKey, DWORD dwIndex, PWSTR pszSubKeyName, DWORD* pcchSubKeyNameLength) throw(CErr);
  78. // @cmember
  79. // intended client is CEnumValues, so lack of F::CStringBuffer support is ok
  80. static void ThrEnumValue(HKEY hKey, DWORD dwIndex, PWSTR pszValueName, DWORD* pcchValueNameLength, DWORD* pdwType, BYTE* pbData, DWORD* pcbData) throw(CErr);
  81. // @cmember query values into
  82. void ThrQueryValuesInfo(DWORD* pcValues, DWORD* pcchMaxValueNameLength, DWORD* cbMaxValueLength) const throw(CErr);
  83. // @cmember Recursively delete keys
  84. void ThrRecurseDeleteKey(LPCWSTR lpszKey) throw(CErr);
  85. // @cmember Delete a sub key
  86. void DeleteSubKey(LPCWSTR lpszSubKey) throw(CErr);
  87. // @cmember FUTURE no clients
  88. //void ThrQuerySubKeysInfo(DWORD* pcSubKeys, DWORD* pcchMaxSubKeyNameLength) const throw(CErr);
  89. // @cmember FUTURE no clients
  90. //void ThrEnumValue(DWORD dwIndex, PWSTR pszValueName, DWORD* pcchValueNameLength, DWORD* pdwType, BYTE* pbData, DWORD* pcbData) const throw(CErr);
  91. // @cmember FUTURE no clients
  92. //void ThrEnumKey(DWORD dwIndex, PWSTR pszSubKeyName, DWORD* pcchSubKeyNameLength) const throw(CErr);
  93. /* FUTURE stuff from ATL 6.0
  94. LONG Close();
  95. HKEY Detach();
  96. void Attach(HKEY hKey);
  97. LONG DeleteValue(LPCTSTR lpszValue);
  98. */
  99. // because there is no documented invalid value for HKEY, we do
  100. // not offer a way to get at the HKEY directly to store over it;
  101. // we must maintain the m_fValid member datum.
  102. // HKEY* PhPointerToUnderlying();
  103. protected:
  104. // @cmember a regular HKEY that we wrap
  105. HKEY m_hKey;
  106. // @cmember
  107. // so that VReadString doesn't call RegQueryInfoKey every time
  108. // invalidated by VSetValue, but we still handle
  109. // ERROR_MORE_DATA in VReadString since this isn't robust
  110. mutable DWORD m_cbMaxValueLength;
  111. // bools at end for alignment reasons
  112. // @cmember since there is no documented invalid value for HKEY, this
  113. // seperate bool indicates if we have a valid value.
  114. bool m_fValid;
  115. // @cmember is m_cbMaxValueLength up to date as far as we know.
  116. mutable bool m_fMaxValueLengthValid;
  117. // @cmember access value is valid
  118. bool m_fKnownSam;
  119. // @cmember keep the access that we opened with.
  120. REGSAM m_samDesired;
  121. // @cmember Needs a definition
  122. operator HKEY() const throw(CErr); // bitwise const, but not necessarily logically const
  123. // @cmember fix up nulls etc
  124. __declspec(nothrow) static VOID
  125. FixBadRegistryStringValue
  126. (
  127. HKEY Key,
  128. PCWSTR ValueName,
  129. DWORD cbActualBufferSize,
  130. LONG lRes,
  131. DWORD dwType,
  132. BYTE* pbData,
  133. DWORD* pcbData
  134. ) /*throw()*/;
  135. // @cmember query info
  136. static VOID
  137. ThrQueryInfo
  138. (
  139. HKEY hKey,
  140. WCHAR* pClass,
  141. DWORD* pcbClass,
  142. DWORD* pReserved,
  143. DWORD* pcSubKeys,
  144. DWORD* pcchMaxSubKeyLength,
  145. DWORD* pcchMaxClassLength,
  146. DWORD* pcValues,
  147. DWORD* pcchMaxValueNameLength,
  148. DWORD* pcbMaxValueDataLength,
  149. DWORD* pcbSecurityDescriptorLength,
  150. FILETIME* pftLastWriteTime
  151. ) throw(CErr);
  152. static void GetKeyNameForDiagnosticPurposes(HKEY, F::CUnicodeBaseStringBuffer &);
  153. private:
  154. CRegKey2(const CRegKey2&); // deliberately not impelemented
  155. void operator=(const CRegKey2&); // deliberately not impelemented
  156. };
  157. } // namespace
  158. #endif // }