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.

135 lines
4.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998.
  5. //
  6. // File: RegAcc.hxx
  7. //
  8. // Contents: 'Simple' registry access
  9. //
  10. // History: 21-Dec-93 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. //+-------------------------------------------------------------------------
  15. //
  16. // Function: Range
  17. //
  18. // Synopsis: Enforces bounds on a value
  19. //
  20. // History: 12-Oct-96 dlee created
  21. //
  22. //--------------------------------------------------------------------------
  23. template<class T> T Range(
  24. T tDefault,
  25. T tMin,
  26. T tMax )
  27. {
  28. return __min( __max( tDefault, tMin ), tMax );
  29. } //Range
  30. //+-------------------------------------------------------------------------
  31. //
  32. // Class: CRegCallBack
  33. //
  34. // Purpose: CallBack class during enumeration
  35. //
  36. // History: 29-Aug-94 SitaramR Created
  37. //
  38. //
  39. //--------------------------------------------------------------------------
  40. class CRegCallBack
  41. {
  42. public:
  43. virtual NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  44. VOID *pValueData, ULONG uValueLength) = 0;
  45. virtual ~CRegCallBack() {}
  46. };
  47. //+-------------------------------------------------------------------------
  48. //
  49. // Class: CRegAccess
  50. //
  51. // Purpose: 'Simple' registry access
  52. //
  53. // History: 21-Dec-93 KyleP Created
  54. // 12-Aug-98 KLam Added DoesKeyExist
  55. // 19-Aug-98 KLam Removed INHERIT_UNWIND & DECLARE_UNWIND
  56. //
  57. // Notes: This class provides read-only access to the registry. It
  58. // will work in both kernel and user mode.
  59. //
  60. //--------------------------------------------------------------------------
  61. class CRegAccess
  62. {
  63. public:
  64. CRegAccess( ULONG ulRelative, WCHAR const * pwcsRegPath );
  65. ~CRegAccess()
  66. {
  67. // CRegAccess is a global object, so this destructor can be called
  68. // potentially before any calls to operator new. Rather than
  69. // waste cycles in every delete, waste them here by checking for 0.
  70. if ( 0 != _wcsPath )
  71. delete [] _wcsPath;
  72. }
  73. void Get( WCHAR const * pwcsValue, WCHAR * wcsVal, unsigned cc );
  74. ULONG Get( WCHAR const * pwcsValue );
  75. ULONG Read( WCHAR const * wcsKey, ULONG ulDefaultValue);
  76. ULONG Read( WCHAR const * wcsKey, ULONG ulDefault,
  77. ULONG ulMin, ULONG ulMax )
  78. {
  79. return Range( Read( wcsKey, ulDefault ), ulMin, ulMax );
  80. }
  81. WCHAR * Read( WCHAR const * wcsKey, WCHAR const * pwcsDefaultValue);
  82. void EnumerateValues( WCHAR *wszValue, CRegCallBack& regCallback );
  83. // BOOL DoesKeyExist( WCHAR const * wcsKey );
  84. private:
  85. static NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  86. void *pValueData, ULONG uValueLength,
  87. void *pContext, void *pEntryContext );
  88. static NTSTATUS CallBackDWORD( WCHAR *pValueName, ULONG uValueType,
  89. void *pValueData, ULONG uValueLength,
  90. void *pContext, void *pEntryContext );
  91. void SetName( WCHAR const * pwc ) { _regtab[0].Name = (WCHAR *)pwc; }
  92. DWORD ReadDWORD( WCHAR const * wcsKey, ULONG *pDefaultValue );
  93. void SetEntryContext( void * p)
  94. {
  95. if ( p == 0 )
  96. {
  97. _regtab[0].EntryContext = 0;
  98. _regtab[0].Flags = RTL_QUERY_REGISTRY_REQUIRED;
  99. }
  100. else
  101. {
  102. _regtab[0].EntryContext = p;
  103. _regtab[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
  104. }
  105. }
  106. ULONG _ulRelative;
  107. WCHAR _wcsPathBuf[100];
  108. WCHAR * _wcsPath;
  109. RTL_QUERY_REGISTRY_TABLE _regtab[2]; // used for strings & enumeration
  110. };