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.

151 lines
4.1 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CRegistryKey.h
  7. //
  8. // Description:
  9. // Header file for CRegistryKey class.
  10. //
  11. // The CRegistry class is the representation of a registry key.
  12. // See IMPORTANT NOTE in the class description.
  13. //
  14. // Implementation Files:
  15. // CRegistryKey.cpp
  16. //
  17. // Maintained By:
  18. // Vij Vasu (Vvasu) 03-MAR-2000
  19. //
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Make sure that this file is included only once per compile path.
  22. #pragma once
  23. //////////////////////////////////////////////////////////////////////////
  24. // Include Files
  25. //////////////////////////////////////////////////////////////////////////
  26. #include <windows.h>
  27. // For smart classes
  28. #include "SmartClasses.h"
  29. //////////////////////////////////////////////////////////////////////////////
  30. //++
  31. //
  32. // class CRegistryKey
  33. //
  34. // Description:
  35. // The CRegistry class is the representation of a registry key.
  36. //
  37. // IMPORTANT NOTE:
  38. // Due to the contained smart handle object, objects of this class
  39. // have destructive copy semantics. That is, copying an object of this
  40. // class will invalidate the source object.
  41. //
  42. //--
  43. //////////////////////////////////////////////////////////////////////////////
  44. class CRegistryKey
  45. {
  46. public:
  47. //////////////////////////////////////////////////////////////////////////
  48. // Constructors and destructors
  49. //////////////////////////////////////////////////////////////////////////
  50. // Default constructor.
  51. CRegistryKey() throw();
  52. // Constructor that opens the key.
  53. CRegistryKey(
  54. HKEY hKeyParentIn
  55. , const WCHAR * pszSubKeyNameIn
  56. , REGSAM samDesiredIn = KEY_ALL_ACCESS
  57. );
  58. // Default destructor.
  59. ~CRegistryKey();
  60. //////////////////////////////////////////////////////////////////////////
  61. // Public methods
  62. //////////////////////////////////////////////////////////////////////////
  63. // Open this key.
  64. void
  65. OpenKey(
  66. HKEY hKeyParentIn
  67. , const WCHAR * pszSubKeyNameIn
  68. , REGSAM samDesiredIn = KEY_ALL_ACCESS
  69. );
  70. // Create this key. Open it if it already exists.
  71. void
  72. CreateKey(
  73. HKEY hKeyParentIn
  74. , const WCHAR * pszSubKeyNameIn
  75. , REGSAM samDesiredIn = KEY_ALL_ACCESS
  76. );
  77. // Read a value under this key.
  78. void QueryValue(
  79. const WCHAR * pszValueNameIn
  80. , LPBYTE * ppbDataOut
  81. , LPDWORD pdwDataSizeBytesOut
  82. , LPDWORD pdwTypeOut = NULL
  83. ) const;
  84. // Write a value under this key.
  85. void SetValue(
  86. const WCHAR * pszValueNameIn
  87. , DWORD dwTypeIn
  88. , const BYTE * cpbDataIn
  89. , DWORD dwDataSizeBytesIn
  90. ) const;
  91. //
  92. // Rename this key.
  93. // Note: This function calls the NtRenameKey API with the handle returned by
  94. // RegOpenKeyEx. This will work as long as we are not dealing with a remote
  95. // registry key.
  96. //
  97. void RenameKey( const WCHAR * pszNewNameIn );
  98. //////////////////////////////////////////////////////////////////////////
  99. // Public accessors
  100. //////////////////////////////////////////////////////////////////////////
  101. // Get the handle to the registry key.
  102. HKEY HGetKey()
  103. {
  104. return m_shkKey.HHandle();
  105. }
  106. private:
  107. //////////////////////////////////////////////////////////////////////////
  108. // Private type definitions
  109. //////////////////////////////////////////////////////////////////////////
  110. // Smart registry key
  111. typedef CSmartResource<
  112. CHandleTrait<
  113. HKEY
  114. , LONG
  115. , RegCloseKey
  116. , reinterpret_cast< HKEY >( NULL )
  117. >
  118. >
  119. SmartHKey;
  120. //////////////////////////////////////////////////////////////////////////
  121. // Private data
  122. //////////////////////////////////////////////////////////////////////////
  123. SmartHKey m_shkKey;
  124. }; //*** class CRegistryKey