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.

113 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. regentry.h
  5. Abstract:
  6. Wrapper for registry access Win32 APIs
  7. Usage:
  8. Construct a RegEntry object by specifying the subkey (under
  9. HKEY_CURRENT_USER by default, but can be overridden.)
  10. All member functions are inline so there is minimal overhead.
  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(). GetNumber()
  19. allows you to specificy a default if the valuename doesn't exist.
  20. DeleteValue() removes the valuename and value pair.
  21. Author:
  22. Vlad Sadovsky (vlads) 26-Jan-1997
  23. Revision History:
  24. 26-Jan-1997 VladS created
  25. --*/
  26. #ifndef REGENTRY_INC
  27. #define REGENTRY_INC
  28. #ifndef STRICT
  29. #define STRICT
  30. #endif
  31. #include <windows.h>
  32. class StiCString;
  33. class RegEntry
  34. {
  35. public:
  36. RegEntry();
  37. RegEntry(const TCHAR *pszSubKey, HKEY hkey = HKEY_CURRENT_USER);
  38. ~RegEntry();
  39. BOOL Open(const TCHAR *pszSubKey, HKEY hkey = HKEY_CURRENT_USER);
  40. BOOL Close();
  41. long GetError() { return m_error; }
  42. long SetValue(const TCHAR *pszValue, const TCHAR *string);
  43. long SetValue(const TCHAR *pszValue, const TCHAR *string, DWORD dwType);
  44. long SetValue(const TCHAR *pszValue, unsigned long dwNumber);
  45. long SetValue(const TCHAR *pszValue, BYTE * pValue,unsigned long dwNumber);
  46. TCHAR* GetString(const TCHAR *pszValue, TCHAR *string, unsigned long length);
  47. VOID GetValue(const TCHAR *pszValueName, BUFFER *pValue);
  48. long GetNumber(const TCHAR *pszValue, long dwDefault = 0);
  49. long DeleteValue(const TCHAR *pszValue);
  50. long FlushKey();
  51. VOID MoveToSubKey(const TCHAR *pszSubKeyName);
  52. BOOL EnumSubKey(DWORD index, StiCString *pStrString);
  53. BOOL GetSubKeyInfo(DWORD *NumberOfSubKeys, DWORD *pMaxSubKeyLength);
  54. HKEY GetKey() { return m_hkey; };
  55. BOOL IsValid() { return bhkeyValid;};
  56. private:
  57. HKEY m_hkey;
  58. long m_error;
  59. BOOL bhkeyValid;
  60. };
  61. class RegEnumValues
  62. {
  63. public:
  64. RegEnumValues(RegEntry *pRegEntry);
  65. ~RegEnumValues();
  66. long Next();
  67. TCHAR * GetName() {return pchName;}
  68. DWORD GetType() {return dwType;}
  69. LPBYTE GetData() {return pbValue;}
  70. DWORD GetDataLength() {return dwDataLength;}
  71. private:
  72. RegEntry * pRegEntry;
  73. DWORD iEnum;
  74. DWORD cEntries;
  75. TCHAR * pchName;
  76. LPBYTE pbValue;
  77. DWORD dwType;
  78. DWORD dwDataLength;
  79. DWORD cMaxValueName;
  80. DWORD cMaxData;
  81. LONG m_error;
  82. };
  83. #endif