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.

131 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 2000-2001 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. //
  14. // KEY_WOW64_64KEY if it is supported on this system, else 0.
  15. //
  16. DWORD FUSIONP_KEY_WOW64_64KEY();
  17. /* this closes RegOpenKey/RegCreateKey */
  18. class COperatorFRegCloseKey
  19. {
  20. public: BOOL operator()(void* handle) const;
  21. };
  22. //
  23. // there isn't an actual invalid value, and HKEY is not HANDLE.
  24. // The right solution is to keep a seperate bool as in \\JayK1\g\vs\src\vsee\lib\Reg.
  25. // See about porting that over.
  26. //
  27. // 3/20/2001 - JonWis - "NULL" really is the "invalid key" value, as I watched
  28. // RegOpenKeyExW fill out its out PHKEY with "NULL" when the tag could not be
  29. // opened.
  30. //
  31. class CRegKey : public CHandleTemplate<&hNull, COperatorFRegCloseKey>
  32. {
  33. private:
  34. typedef CHandleTemplate<&hNull, COperatorFRegCloseKey> Base;
  35. public:
  36. CRegKey(void* handle = GetInvalidValue()) : Base(handle) { }
  37. operator HKEY() const { return reinterpret_cast<HKEY>(m_handle); }
  38. void operator=(HKEY hkValue) { return Base::operator=(hkValue); }
  39. BOOL OpenOrCreateSubKey(
  40. OUT CRegKey& Target,
  41. IN PCWSTR SubKeyName,
  42. IN REGSAM rsDesiredAccess = KEY_ALL_ACCESS,
  43. IN DWORD dwOptions = 0,
  44. IN PDWORD pdwDisposition = NULL,
  45. IN PWSTR pwszClass = NULL) const;
  46. BOOL OpenSubKey( OUT CRegKey& Target, IN PCWSTR SubKeyName, REGSAM rsAccess = KEY_READ, DWORD ulOptions = 0) const;
  47. BOOL EnumKey( IN DWORD dwIndex, OUT CBaseStringBuffer& rbuffKeyName, PFILETIME pftLastWriteTime = NULL, PBOOL pbNoMoreItems = NULL ) const;
  48. BOOL LargestSubItemLengths( PDWORD pdwSubkeyLength = NULL, PDWORD pdwValueLength = NULL ) const;
  49. BOOL EnumValue( IN DWORD dwIndex, OUT CBaseStringBuffer& rbuffValueName, LPDWORD lpdwType = NULL, PBYTE pbData = NULL, PDWORD pdwcbData = NULL, PBOOL pbNoMoreItems = NULL );
  50. BOOL SetValue(IN PCWSTR pcwszValueName, IN DWORD dwRegType, IN const BYTE *pbData, IN SIZE_T cbDataLength) const;
  51. BOOL SetValue(IN PCWSTR pcwszValueName, IN const CBaseStringBuffer &rcbuffValueValue) const;
  52. BOOL SetValue(IN PCWSTR pcwszValueName, IN DWORD dwValue) const;
  53. BOOL DeleteValue(IN PCWSTR pcwszValueName, OUT DWORD &rdwWin32Error, SIZE_T cExceptionalWin32Errors, ...) const;
  54. BOOL DeleteValue(IN PCWSTR pcwszValueName) const;
  55. BOOL DeleteKey( IN PCWSTR pcwszValue );
  56. BOOL DestroyKeyTree();
  57. BOOL Save( IN PCWSTR TargetFilePath, IN DWORD dwFlags = REG_LATEST_FORMAT, IN LPSECURITY_ATTRIBUTES pSecAttrsOnTargetFile = NULL );
  58. BOOL Restore( IN PCWSTR SourceFilePath, DWORD dwFlags );
  59. static HKEY GetInvalidValue() { return reinterpret_cast<HKEY>(Base::GetInvalidValue()); }
  60. private:
  61. void operator =(const HANDLE);
  62. CRegKey(const CRegKey &); // intentionally not implemented
  63. void operator =(const CRegKey &); // intentionally not implemented
  64. };
  65. /*--------------------------------------------------------------------------
  66. inline implementation
  67. --------------------------------------------------------------------------*/
  68. inline BOOL COperatorFRegCloseKey::operator()(void* handle) const
  69. {
  70. HKEY hk = reinterpret_cast<HKEY>(handle);
  71. if ( ( hk != NULL ) && ( hk != INVALID_HANDLE_VALUE ) )
  72. {
  73. LONG lRet = ::RegCloseKey(reinterpret_cast<HKEY>(handle));
  74. if (lRet == NO_ERROR)
  75. return true;
  76. ::FusionpSetLastWin32Error(lRet);
  77. return false;
  78. }
  79. return true;
  80. }
  81. #if defined(FUSION_WIN)
  82. #define FUSIONP_KEY_WOW64_64KEY KEY_WOW64_64KEY
  83. inline DWORD FusionpKeyWow6464key() { return KEY_WOW64_64KEY; }
  84. #else
  85. #include "fusionversion.h"
  86. inline DWORD FusionpKeyWow6464key()
  87. {
  88. static DWORD dwResult;
  89. static BOOL fInited;
  90. if (!fInited)
  91. {
  92. //
  93. // GetVersion gets the significance wrong, returning 0x0105 in the lower word.
  94. // As well since these functions say WindowsNt in their names, they return 0 for Win9x.
  95. //
  96. DWORD dwVersion = (FusionpGetWindowsNtMajorVersion() << 8) | FusionpGetWindowsNtMinorVersion();
  97. if (dwVersion >= 0x0501)
  98. {
  99. dwResult = KEY_WOW64_64KEY;
  100. }
  101. fInited = TRUE;
  102. }
  103. return dwResult;
  104. }
  105. #define FUSIONP_KEY_WOW64_64KEY FusionpKeyWow6464key()
  106. #endif