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.

156 lines
4.4 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 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( void ) 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( void );
  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. // Delete a value under this key.
  99. void DeleteValue(
  100. const WCHAR * pszValueNameIn
  101. ) const;
  102. //////////////////////////////////////////////////////////////////////////
  103. // Public accessors
  104. //////////////////////////////////////////////////////////////////////////
  105. // Get the handle to the registry key.
  106. HKEY HGetKey()
  107. {
  108. return m_shkKey.HHandle();
  109. }
  110. private:
  111. //////////////////////////////////////////////////////////////////////////
  112. // Private type definitions
  113. //////////////////////////////////////////////////////////////////////////
  114. // Smart registry key
  115. typedef CSmartResource<
  116. CHandleTrait<
  117. HKEY
  118. , LONG
  119. , RegCloseKey
  120. , reinterpret_cast< HKEY >( NULL )
  121. >
  122. >
  123. SmartHKey;
  124. //////////////////////////////////////////////////////////////////////////
  125. // Private data
  126. //////////////////////////////////////////////////////////////////////////
  127. SmartHKey m_shkKey;
  128. }; //*** class CRegistryKey