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.

138 lines
4.2 KiB

  1. #ifndef _REGISTRY_H_
  2. #define _REGISTRY_H_
  3. /****************************************************************************
  4. REGISTRY.H
  5. ****************************************************************************/
  6. // Forward declarations
  7. class CRegKey ;
  8. class CRegValueIter ;
  9. class CRegKeyIter ;
  10. // Maximum size of a Registry class name
  11. #define CREGKEY_MAX_CLASS_NAME MAX_PATH
  12. // Wrapper for a Registry key handle.
  13. class CRegKey : public CObject
  14. {
  15. protected:
  16. HKEY m_hKey ;
  17. DWORD m_dwDisposition ;
  18. // Prepare to read a value by finding the value's size.
  19. LONG PrepareValue ( LPCTSTR pchValueName,
  20. DWORD * pdwType,
  21. DWORD * pcbSize,
  22. BYTE ** ppbData ) ;
  23. // Convert a CByteArray to a REG_BINARY block
  24. static LONG FlattenValue ( CByteArray & abData,
  25. DWORD * pcbSize,
  26. BYTE ** ppbData ) ;
  27. public:
  28. // Key information return structure
  29. typedef struct
  30. {
  31. TCHAR chBuff [CREGKEY_MAX_CLASS_NAME] ;
  32. DWORD dwClassNameSize,
  33. dwNumSubKeys,
  34. dwMaxSubKey,
  35. dwMaxClass,
  36. dwMaxValues,
  37. dwMaxValueName,
  38. dwMaxValueData,
  39. dwSecDesc ;
  40. FILETIME ftKey ;
  41. } CREGKEY_KEY_INFO ;
  42. // Standard constructor for an existing key
  43. CRegKey ( HKEY hKeyBase,
  44. LPCTSTR pchSubKey = NULL,
  45. REGSAM regSam = KEY_ALL_ACCESS ) ;
  46. // Constructor creating a new key.
  47. CRegKey ( LPCTSTR lpSubKey,
  48. HKEY hKeyBase,
  49. LPCTSTR lpValueName = NULL,
  50. DWORD dwType = 0,
  51. LPBYTE lpValueData = NULL,
  52. DWORD cbValueData = 0);
  53. ~ CRegKey () ;
  54. // Allow a CRegKey to be used anywhere an HKEY is required.
  55. operator HKEY ()
  56. { return m_hKey ; }
  57. // Fill a key information structure
  58. LONG QueryKeyInfo ( CREGKEY_KEY_INFO * pRegKeyInfo ) ;
  59. // Overloaded value query members; each returns ERROR_INVALID_PARAMETER
  60. // if data exists but not in correct form to deliver into result object.
  61. LONG QueryValue ( LPCTSTR pchValueName, CString & strResult ) ;
  62. LONG QueryValue ( LPCTSTR pchValueName, CStringList & strList ) ;
  63. LONG QueryValue ( LPCTSTR pchValueName, DWORD & dwResult ) ;
  64. LONG QueryValue ( LPCTSTR pchValueName, CByteArray & abResult ) ;
  65. LONG QueryValue ( LPCTSTR pchValueName, void * pvResult, DWORD cbSize );
  66. LONG QueryValue ( LPCTSTR pchValueName, LPTSTR szMultiSz, DWORD dwSize );
  67. // Overloaded value setting members.
  68. LONG SetValue ( LPCTSTR pchValueName, LPCTSTR szResult, BOOL fExpand = FALSE ) ;
  69. LONG SetValue ( LPCTSTR pchValueName, DWORD dwResult ) ;
  70. LONG SetValue ( LPCTSTR pchValueName, CByteArray & abResult ) ;
  71. LONG SetValue ( LPCTSTR pchValueName, void * pvResult, DWORD cbSize );
  72. LONG SetValue ( LPCTSTR pchValueName, LPCTSTR szMultiSz, DWORD dwSize );
  73. LONG DeleteValue( LPCTSTR pchKeyName );
  74. LONG DeleteTree( LPCTSTR pchKeyName );
  75. };
  76. // Iterate the values of a key, return the name and type
  77. // of each.
  78. class CRegValueIter : public CObject
  79. {
  80. protected:
  81. CRegKey & m_rk_iter ;
  82. DWORD m_dw_index ;
  83. TCHAR * m_p_buffer ;
  84. DWORD m_cb_buffer ;
  85. public:
  86. CRegValueIter ( CRegKey & regKey ) ;
  87. ~ CRegValueIter () ;
  88. // Get the name (and optional last write time) of the next key.
  89. LONG Next ( CString * pstrName, DWORD * pdwType ) ;
  90. LONG Next ( CString * pstrName, CString * pstrValue );
  91. // Reset the iterator
  92. void Reset ()
  93. { m_dw_index = 0 ; }
  94. };
  95. // Iterate the sub-key names of a key.
  96. class CRegKeyIter : public CObject
  97. {
  98. protected:
  99. CRegKey & m_rk_iter ;
  100. DWORD m_dw_index ;
  101. TCHAR * m_p_buffer ;
  102. DWORD m_cb_buffer ;
  103. public:
  104. CRegKeyIter ( CRegKey & regKey ) ;
  105. ~ CRegKeyIter () ;
  106. // Get the name (and optional last write time) of the next key.
  107. LONG Next ( CString * pstrName, CTime * pTime = NULL ) ;
  108. // Reset the iterator
  109. void Reset ()
  110. { m_dw_index = 0 ; }
  111. };
  112. #endif // _REGISTRY_H_