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.

140 lines
4.3 KiB

  1. /****************************************************************************
  2. REGISTRY.H
  3. ****************************************************************************/
  4. #ifndef _registry_h
  5. #define _registry_h
  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 ( const TCHAR * pchValueName,
  20. DWORD * pdwType,
  21. DWORD * pcbSize,
  22. BYTE ** ppbData ) ;
  23. // Convert a CStringList to the REG_MULTI_SZ format
  24. static LONG FlattenValue ( CStringList & strList,
  25. DWORD * pcbSize,
  26. BYTE ** ppbData ) ;
  27. // Convert a CByteArray to a REG_BINARY block
  28. static LONG FlattenValue ( CByteArray & abData,
  29. DWORD * pcbSize,
  30. BYTE ** ppbData ) ;
  31. public:
  32. // Key information return structure
  33. typedef struct
  34. {
  35. TCHAR chBuff [CREGKEY_MAX_CLASS_NAME] ;
  36. DWORD dwClassNameSize,
  37. dwNumSubKeys,
  38. dwMaxSubKey,
  39. dwMaxClass,
  40. dwMaxValues,
  41. dwMaxValueName,
  42. dwMaxValueData,
  43. dwSecDesc ;
  44. FILETIME ftKey ;
  45. } CREGKEY_KEY_INFO ;
  46. // Standard constructor for an existing key
  47. CRegKey ( HKEY hKeyBase,
  48. const TCHAR * pchSubKey = NULL,
  49. REGSAM regSam = KEY_ALL_ACCESS,
  50. const TCHAR * pchServerName = NULL ) ;
  51. // Constructor creating a new key.
  52. CRegKey ( const TCHAR * pchSubKey,
  53. HKEY hKeyBase,
  54. DWORD dwOptions = 0,
  55. REGSAM regSam = KEY_ALL_ACCESS,
  56. LPSECURITY_ATTRIBUTES pSecAttr = NULL,
  57. const TCHAR * pchServerName = NULL ) ;
  58. ~ CRegKey () ;
  59. // Allow a CRegKey to be used anywhere an HKEY is required.
  60. operator HKEY ()
  61. { return m_hKey ; }
  62. // Fill a key information structure
  63. LONG QueryKeyInfo ( CREGKEY_KEY_INFO * pRegKeyInfo ) ;
  64. // Overloaded value query members; each returns ERROR_INVALID_PARAMETER
  65. // if data exists but not in correct form to deliver into result object.
  66. LONG QueryValue ( const TCHAR * pchValueName, CString & strResult ) ;
  67. LONG QueryValue ( const TCHAR * pchValueName, CStringList & strList ) ;
  68. LONG QueryValue ( const TCHAR * pchValueName, DWORD & dwResult ) ;
  69. LONG QueryValue ( const TCHAR * pchValueName, CByteArray & abResult ) ;
  70. LONG QueryValue ( const TCHAR * pchValueName, void * pvResult, DWORD cbSize );
  71. // Overloaded value setting members.
  72. LONG SetValue ( const TCHAR * pchValueName, CString & strResult ) ;
  73. LONG SetValue ( const TCHAR * pchValueName, CStringList & strList ) ;
  74. LONG SetValue ( const TCHAR * pchValueName, DWORD & dwResult ) ;
  75. LONG SetValue ( const TCHAR * pchValueName, CByteArray & abResult ) ;
  76. LONG SetValue ( const TCHAR * pchValueName, void * pvResult, DWORD cbSize );
  77. LONG DeleteValue ( const TCHAR * pchValueName);
  78. };
  79. // Iterate the values of a key, return the name and type
  80. // of each.
  81. class CRegValueIter : public CObject
  82. {
  83. protected:
  84. CRegKey & m_rk_iter ;
  85. DWORD m_dw_index ;
  86. TCHAR * m_p_buffer ;
  87. DWORD m_cb_buffer ;
  88. public:
  89. CRegValueIter ( CRegKey & regKey ) ;
  90. ~ CRegValueIter () ;
  91. // Get the name (and optional last write time) of the next key.
  92. LONG Next ( CString * pstrName, DWORD * pdwType ) ;
  93. // Reset the iterator
  94. void Reset ()
  95. { m_dw_index = 0 ; }
  96. };
  97. // Iterate the sub-key names of a key.
  98. class CRegKeyIter : public CObject
  99. {
  100. protected:
  101. CRegKey & m_rk_iter ;
  102. DWORD m_dw_index ;
  103. TCHAR * m_p_buffer ;
  104. DWORD m_cb_buffer ;
  105. public:
  106. CRegKeyIter ( CRegKey & regKey ) ;
  107. ~ CRegKeyIter () ;
  108. // Get the name (and optional last write time) of the next key.
  109. LONG Next ( CString * pstrName, CTime * pTime = NULL ) ;
  110. // Reset the iterator
  111. void Reset ()
  112. { m_dw_index = 0 ; }
  113. };
  114. #endif