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.

211 lines
5.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. regkey.h
  7. FILE HISTORY:
  8. */
  9. #ifndef _TREGKEY_H
  10. #define _TREGKEY_H
  11. #if _MSC_VER >= 1000 // VC 5.0 or later
  12. #pragma once
  13. #endif
  14. //
  15. // Maximum size of a Registry class name
  16. //
  17. #define CREGKEY_MAX_CLASS_NAME MAX_PATH
  18. #ifndef TFS_EXPORT_CLASS
  19. #define TFS_EXPORT_CLASS
  20. #endif
  21. // Convert a CStringList to the REG_MULTI_SZ format
  22. DWORD StrList2MULTI_SZ(CStringList & strList, DWORD * pcbSize, BYTE ** ppbData);
  23. // Convert a REG_MULTI_SZ format to the CStringList
  24. DWORD MULTI_SZ2StrList(LPCTSTR pbMulti_Sz, CStringList & strList);
  25. //
  26. // Wrapper for a Registry key handle.
  27. //
  28. class TFS_EXPORT_CLASS RegKey
  29. {
  30. public:
  31. //
  32. // Key information return structure
  33. //
  34. typedef struct
  35. {
  36. TCHAR chBuff [CREGKEY_MAX_CLASS_NAME] ;
  37. DWORD dwClassNameSize, // size of the class string
  38. dwNumSubKeys, // number of subkeys
  39. dwMaxSubKey, // longest subkey name length
  40. dwMaxClass, // longest class string length
  41. dwMaxValues, // number of value entries
  42. dwMaxValueName, // longest value name length
  43. dwMaxValueData, // longest value data length
  44. dwSecDesc ; // security descriptor length
  45. FILETIME ftKey ;
  46. } CREGKEY_KEY_INFO ;
  47. // Standard constructor
  48. // To get at keys, you will have to open/create the key
  49. RegKey();
  50. ~RegKey ();
  51. DWORD Create(HKEY hKeyParent,
  52. LPCTSTR lpszKeyName,
  53. DWORD dwOptions = REG_OPTION_NON_VOLATILE,
  54. REGSAM samDesired = KEY_ALL_ACCESS,
  55. LPSECURITY_ATTRIBUTES lpSecAttr = NULL,
  56. LPCTSTR pszServerName = NULL);
  57. DWORD Open(HKEY hKeyParent,
  58. LPCTSTR pszSubKey,
  59. REGSAM samDesired = KEY_ALL_ACCESS,
  60. LPCTSTR pszServerName = NULL);
  61. DWORD Close();
  62. HKEY Detach();
  63. void Attach(HKEY hKey);
  64. DWORD DeleteSubKey(LPCTSTR lpszSubKey);
  65. DWORD RecurseDeleteKey(LPCTSTR lpszKey);
  66. DWORD DeleteValue(LPCTSTR lpszValue);
  67. // Deletes the subkeys of the current key (does NOT delete the
  68. // current key).
  69. DWORD RecurseDeleteSubKeys();
  70. //
  71. // Allow a RegKey to be used anywhere an HKEY is required.
  72. //
  73. operator HKEY () const
  74. {
  75. return m_hKey ;
  76. }
  77. //
  78. // Fill a key information structure
  79. //
  80. DWORD QueryKeyInfo ( CREGKEY_KEY_INFO * pRegKeyInfo ) ;
  81. DWORD QueryTypeAndSize(LPCTSTR pszValueName, DWORD *pdwType, DWORD *pdwSize);
  82. //
  83. // Overloaded value query members; each returns ERROR_INVALID_PARAMETER
  84. // if data exists but not in correct form to deliver into result object.
  85. //
  86. DWORD QueryValue ( LPCTSTR pchValueName, CString & strResult ) ;
  87. DWORD QueryValue ( LPCTSTR pchValueName, CStringList & strList ) ;
  88. DWORD QueryValue ( LPCTSTR pchValueName, DWORD & dwResult ) ;
  89. DWORD QueryValue ( LPCTSTR pchValueName, CByteArray & abResult ) ;
  90. DWORD QueryValue ( LPCTSTR pchValueName, void * pvResult, DWORD cbSize );
  91. DWORD QueryValue ( LPCTSTR pchValueName, LPTSTR pszDestBuffer, DWORD cbSize, BOOL fExpandSz);
  92. DWORD QueryValueExplicit(LPCTSTR pchValueName,
  93. DWORD *pdwType,
  94. DWORD *pdwSize,
  95. LPBYTE *ppbData);
  96. // Overloaded value setting members.
  97. DWORD SetValue ( LPCTSTR pchValueName, LPCTSTR pszValue,
  98. BOOL fRegExpand = FALSE) ;
  99. DWORD SetValue ( LPCTSTR pchValueName, CStringList & strList ) ;
  100. DWORD SetValue ( LPCTSTR pchValueName, DWORD & dwResult ) ;
  101. DWORD SetValue ( LPCTSTR pchValueName, CByteArray & abResult ) ;
  102. DWORD SetValue ( LPCTSTR pchValueName, void * pvResult, DWORD cbSize );
  103. DWORD SetValueExplicit(LPCTSTR pchValueName,
  104. DWORD dwType,
  105. DWORD dwSize,
  106. LPBYTE pbData);
  107. protected:
  108. HKEY m_hKey;
  109. // Prepare to read a value by finding the value's size.
  110. DWORD PrepareValue (
  111. LPCTSTR pchValueName,
  112. DWORD * pdwType,
  113. DWORD * pcbSize,
  114. BYTE ** ppbData
  115. );
  116. // Convert a CStringList to the REG_MULTI_SZ format
  117. static DWORD FlattenValue (
  118. CStringList & strList,
  119. DWORD * pcbSize,
  120. BYTE ** ppbData
  121. );
  122. // Convert a CByteArray to a REG_BINARY block
  123. static DWORD FlattenValue (
  124. CByteArray & abData,
  125. DWORD * pcbSize,
  126. BYTE ** ppbData
  127. );
  128. };
  129. //
  130. // Iterate the values of a key, return the name and type
  131. // of each.
  132. //
  133. class TFS_EXPORT_CLASS RegValueIterator
  134. {
  135. protected:
  136. RegKey * m_pRegKey;
  137. DWORD m_dwIndex ;
  138. TCHAR * m_pszBuffer ;
  139. DWORD m_cbBuffer ;
  140. public:
  141. RegValueIterator();
  142. ~ RegValueIterator () ;
  143. HRESULT Init(RegKey *pRegKey);
  144. //
  145. // Get the name (and optional last write time) of the next key.
  146. //
  147. HRESULT Next ( CString * pstName, DWORD * pdwType ) ;
  148. //
  149. // Reset the iterator
  150. //
  151. void Reset ()
  152. {
  153. m_dwIndex = 0 ;
  154. }
  155. };
  156. //
  157. // Iterate the sub-key names of a key.
  158. //
  159. class TFS_EXPORT_CLASS RegKeyIterator
  160. {
  161. public:
  162. RegKeyIterator();
  163. ~RegKeyIterator();
  164. HRESULT Init(RegKey *pRegKey);
  165. HRESULT Next(CString *pstName, CTime *pTime = NULL);
  166. HRESULT Reset();
  167. protected:
  168. RegKey * m_pregkey;
  169. DWORD m_dwIndex;
  170. TCHAR * m_pszBuffer;
  171. DWORD m_cbBuffer;
  172. };
  173. #endif _TREGKEY_H