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.

137 lines
3.8 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1995-1996 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. regentry.h
  7. Oct. 95 LenS
  8. Wrapper for registry access
  9. Construct a RegEntry object by specifying the subkey (under
  10. HKEY_CURRENT_USER by default, but can be overridden.)
  11. All member functions (except the destructor) set an internal
  12. error state which can be retrieved with GetError().
  13. Zero indicates no error.
  14. RegEntry works only with strings and DWORDS which are both set
  15. using the overloaded function SetValue()
  16. SetValue("valuename", "string");
  17. SetValue("valuename", 42);
  18. Values are retrieved with GetString() and GetNumber().
  19. GetNumber() allows you to specificy a default if the valuename doesn't
  20. exist.
  21. GetString() returns a pointer to a string internal to RegEntry that is
  22. invalidated when another fuction is called on the same RegEntry object
  23. (e.g. its destructor) so, if you want to use the string beyond this
  24. time, then you must copy it out of the RegEntry object first.
  25. DeleteValue() removes the valuename and value pair.
  26. Registry flushes are automatic when RegEntry is destroys or moves to
  27. another key.
  28. ****************************************************************************/
  29. #ifndef REGENTRY_INC
  30. #define REGENTRY_INC
  31. class RegEntry
  32. {
  33. public:
  34. RegEntry( LPCTSTR pszSubKey,
  35. HKEY hkey = HKEY_CURRENT_USER,
  36. BOOL fCreate = TRUE,
  37. REGSAM samDesired = 0
  38. );
  39. ~RegEntry();
  40. long GetError() { return m_error;}
  41. VOID ClearError() {m_error = ERROR_SUCCESS;}
  42. long SetValue(LPCTSTR pszValueName, LPCTSTR string);
  43. long SetValue(LPCTSTR pszValueName, unsigned long dwNumber);
  44. long SetValue(LPCTSTR pszValue, void* pData, DWORD cbLength);
  45. LPTSTR GetString(LPCTSTR pszValueName);
  46. DWORD GetBinary(LPCTSTR pszValueName, void** ppvData);
  47. long GetNumber(LPCTSTR pszValueName, long dwDefault = 0);
  48. ULONG GetNumberIniStyle(LPCTSTR pszValueName, ULONG dwDefault = 0);
  49. long DeleteValue(LPCTSTR pszValueName);
  50. long FlushKey();
  51. VOID MoveToSubKey(LPCTSTR pszSubKeyName);
  52. HKEY GetKey() { return m_hkey; }
  53. private:
  54. VOID ChangeKey(HKEY hNewKey);
  55. VOID UpdateWrittenStatus();
  56. VOID ResizeValueBuffer(DWORD length);
  57. HKEY m_hkey;
  58. long m_error;
  59. BOOL m_fhkeyValid;
  60. LPBYTE m_pbValueBuffer;
  61. DWORD m_cbValueBuffer;
  62. BOOL m_fValuesWritten;
  63. TCHAR m_szNULL;
  64. };
  65. inline long
  66. RegEntry::FlushKey()
  67. {
  68. if (m_fhkeyValid) {
  69. m_error = ::RegFlushKey(m_hkey);
  70. }
  71. return m_error;
  72. }
  73. class RegEnumValues
  74. {
  75. public:
  76. RegEnumValues(RegEntry *pRegEntry);
  77. ~RegEnumValues();
  78. long Next();
  79. LPTSTR GetName() {return m_pchName;}
  80. DWORD GetType() {return m_dwType;}
  81. LPBYTE GetData() {return m_pbValue;}
  82. DWORD GetDataLength() {return m_dwDataLength;}
  83. DWORD GetCount() {return m_cEntries;}
  84. private:
  85. RegEntry * m_pRegEntry;
  86. DWORD m_iEnum;
  87. DWORD m_cEntries;
  88. LPTSTR m_pchName;
  89. LPBYTE m_pbValue;
  90. DWORD m_dwType;
  91. DWORD m_dwDataLength;
  92. DWORD m_cMaxValueName;
  93. DWORD m_cMaxData;
  94. LONG m_error;
  95. };
  96. class RegEnumSubKeys
  97. {
  98. public:
  99. RegEnumSubKeys(RegEntry *pRegEntry);
  100. ~RegEnumSubKeys();
  101. long Next();
  102. LPTSTR GetName() {return m_pchName;}
  103. DWORD GetCount() {return m_cEntries;}
  104. protected:
  105. RegEntry * m_pRegEntry;
  106. DWORD m_iEnum;
  107. DWORD m_cEntries;
  108. LPTSTR m_pchName;
  109. DWORD m_cMaxKeyName;
  110. LONG m_error;
  111. };
  112. #endif // REGENTRY_INC