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.

158 lines
5.4 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. fusionreg.h
  5. Abstract:
  6. registry pieces of FusionHandle
  7. other registry stuff -- Win2000 32bit-on-64bit support
  8. Author:
  9. Jay Krell (JayKrell) April 2001
  10. Revision History:
  11. --*/
  12. #pragma once
  13. namespace F
  14. {
  15. BOOL RegistryTypeDwordToString(DWORD, PCWSTR &);
  16. BOOL RegistryTypeStringToDword(PCWSTR, DWORD &);
  17. BOOL RegistryBuiltinRootToString(HKEY, PCWSTR &);
  18. BOOL RegistryBuiltinStringToRoot(PCWSTR, HKEY &);
  19. }
  20. #ifndef FUSION_ARRAY_DEFINED
  21. #define FUSION_ARRAY_DEFINED
  22. template <typename TStored, typename TPassed = TStored, bool fExponentialGrowth = false, int nDefaultSize = 0, int nGrowthParam = 1>
  23. #else
  24. template <typename TStored, typename TPassed, bool fExponentialGrowth, int nDefaultSize, int nGrowthParam>
  25. #endif
  26. class CFusionArray;
  27. //
  28. // KEY_WOW64_64KEY if it is supported on this system, else 0.
  29. //
  30. DWORD FUSIONP_KEY_WOW64_64KEY();
  31. /* this closes RegOpenKey/RegCreateKey */
  32. class COperatorFRegCloseKey
  33. {
  34. public: BOOL operator()(void* handle) const;
  35. };
  36. //
  37. // there isn't an actual invalid value, and HKEY is not HANDLE.
  38. // The right solution is to keep a seperate bool as in \\JayK1\g\vs\src\vsee\lib\Reg.
  39. // See about porting that over.
  40. //
  41. // 3/20/2001 - JonWis - "NULL" really is the "invalid key" value, as I watched
  42. // RegOpenKeyExW fill out its out PHKEY with "NULL" when the tag could not be
  43. // opened.
  44. //
  45. class CRegKey : public CHandleTemplate<&hNull, COperatorFRegCloseKey>
  46. {
  47. private:
  48. typedef CHandleTemplate<&hNull, COperatorFRegCloseKey> Base;
  49. public:
  50. ~CRegKey() { }
  51. CRegKey(void* handle = GetInvalidValue()) : Base(handle) { }
  52. operator HKEY() const { return reinterpret_cast<HKEY>(m_handle); }
  53. void operator=(HKEY hkValue) { return Base::operator=(hkValue); }
  54. BOOL OpenOrCreateSubKey(
  55. OUT CRegKey &Target,
  56. IN PCWSTR SubKeyName,
  57. IN REGSAM rsDesiredAccess = KEY_ALL_ACCESS,
  58. IN DWORD dwOptions = 0,
  59. IN PDWORD pdwDisposition = NULL,
  60. IN PWSTR pwszClass = NULL) const;
  61. BOOL OpenSubKey( OUT CRegKey &Target, IN PCWSTR SubKeyName, REGSAM rsAccess = KEY_READ, DWORD ulOptions = 0) const;
  62. BOOL EnumKey( IN DWORD dwIndex, OUT CBaseStringBuffer &rbuffKeyName, PFILETIME pftLastWriteTime = NULL, PBOOL pbNoMoreItems = NULL ) const;
  63. /*
  64. NTRAID#NTBUG9-591714-2002/03/31-JayKrell
  65. use of CRegKey::LargestSubItemLengths invites race conditions
  66. */
  67. BOOL LargestSubItemLengths( PDWORD pdwSubkeyLength = NULL, PDWORD pdwValueLength = NULL ) const;
  68. BOOL EnumValue(IN DWORD dwIndex, OUT CBaseStringBuffer &rbuffValueName, LPDWORD lpdwType = NULL, PBOOL pbNoMoreItems = NULL );
  69. BOOL SetValue(IN PCWSTR pcwszValueName, IN DWORD dwRegType, IN const BYTE *pbData, IN SIZE_T cbDataLength) const;
  70. BOOL SetValue(IN PCWSTR pcwszValueName, IN const CBaseStringBuffer &rcbuffValueValue) const;
  71. BOOL SetValue(IN PCWSTR pcwszValueName, IN DWORD dwValue) const;
  72. BOOL DeleteValue(IN PCWSTR pcwszValueName, OUT DWORD &rdwWin32Error, SIZE_T cExceptionalWin32Errors, ...) const;
  73. BOOL DeleteValue(IN PCWSTR pcwszValueName) const;
  74. BOOL DeleteKey( IN PCWSTR pcwszValue );
  75. BOOL DestroyKeyTree();
  76. BOOL GetValue(IN PCWSTR pcwszValueName, OUT CBaseStringBuffer &rbuffValueData);
  77. BOOL GetValue(IN const CBaseStringBuffer &rbuffValueName, OUT CBaseStringBuffer &rbuffValueData);
  78. BOOL GetValue(IN PCWSTR pcwszValueName, OUT CFusionArray<BYTE> &);
  79. BOOL GetValue(IN const CBaseStringBuffer &pcwszValueName, OUT CFusionArray<BYTE> &);
  80. BOOL Save( IN PCWSTR TargetFilePath, IN DWORD dwFlags = REG_LATEST_FORMAT, IN LPSECURITY_ATTRIBUTES pSecAttrsOnTargetFile = NULL );
  81. BOOL Restore( IN PCWSTR SourceFilePath, DWORD dwFlags );
  82. static HKEY GetInvalidValue() { return reinterpret_cast<HKEY>(Base::GetInvalidValue()); }
  83. private:
  84. void operator =(const HANDLE);
  85. CRegKey(const CRegKey &); // intentionally not implemented
  86. void operator =(const CRegKey &); // intentionally not implemented
  87. };
  88. /*--------------------------------------------------------------------------
  89. inline implementation
  90. --------------------------------------------------------------------------*/
  91. inline BOOL COperatorFRegCloseKey::operator()(void* handle) const
  92. {
  93. HKEY hk = reinterpret_cast<HKEY>(handle);
  94. if ((hk != NULL) && (hk != INVALID_HANDLE_VALUE))
  95. {
  96. LONG lRet = ::RegCloseKey(reinterpret_cast<HKEY>(handle));
  97. if (lRet == NO_ERROR)
  98. return true;
  99. ::FusionpSetLastWin32Error(lRet);
  100. return false;
  101. }
  102. return true;
  103. }
  104. #if defined(FUSION_WIN)
  105. #define FUSIONP_KEY_WOW64_64KEY KEY_WOW64_64KEY
  106. inline DWORD FusionpKeyWow6464key() { return KEY_WOW64_64KEY; }
  107. #else
  108. #include "fusionversion.h"
  109. inline DWORD FusionpKeyWow6464key()
  110. {
  111. static DWORD dwResult;
  112. static BOOL fInited;
  113. if (!fInited)
  114. {
  115. //
  116. // GetVersion gets the significance wrong, returning 0x0105 in the lower word.
  117. // As well since these functions say WindowsNt in their names, they return 0 for Win9x.
  118. //
  119. DWORD dwVersion = (FusionpGetWindowsNtMajorVersion() << 8) | FusionpGetWindowsNtMinorVersion();
  120. if (dwVersion >= 0x0501)
  121. {
  122. dwResult = KEY_WOW64_64KEY;
  123. }
  124. fInited = TRUE;
  125. }
  126. return dwResult;
  127. }
  128. #define FUSIONP_KEY_WOW64_64KEY FusionpKeyWow6464key()
  129. #endif