Source code of Windows XP (NT5)
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.

112 lines
3.0 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991-1994 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. regentry.h
  7. Mar. 94 JimH
  8. Mar. 94 LenS Added NLS_STR form of GetStringValue
  9. Mar. 94 LenS Added MoveToSubKey
  10. Mar. 94 LenS Added RegEnumValues class
  11. Mar. 94 LenS Added NPMachineEntries class
  12. hard tabs at 4
  13. Wrapper for registry access
  14. Construct a RegEntry object by specifying the subkey (under
  15. HKEY_CURRENT_USER by default, but can be overridden.)
  16. All member functions are inline so there is minimal overhead.
  17. All member functions (except the destructor) set an internal
  18. error state which can be retrieved with GetError().
  19. Zero indicates no error.
  20. RegEntry works only with strings and DWORDS which are both set
  21. using the overloaded function SetValue()
  22. SetValue("valuename", "string");
  23. SetValue("valuename", 42);
  24. Values are retrieved with GetString() and GetNumber(). GetNumber()
  25. allows you to specificy a default if the valuename doesn't exist.
  26. DeleteValue() removes the valuename and value pair.
  27. ****************************************************************************/
  28. #ifndef REGENTRY_INC
  29. #define REGENTRY_INC
  30. #ifndef STRICT
  31. #define STRICT
  32. #endif
  33. #include <windows.h>
  34. #include <npstring.h>
  35. class RegEntry
  36. {
  37. public:
  38. RegEntry(const char *pszSubKey, HKEY hkey = HKEY_CURRENT_USER);
  39. ~RegEntry();
  40. long GetError() { return _error; }
  41. long SetValue(const char *pszValue, const char *string);
  42. long SetValue(const char *pszValue, unsigned long dwNumber);
  43. char * GetString(const char *pszValue, char *string, unsigned long length);
  44. VOID GetValue(const char *pszValueName, NLS_STR *pnlsString);
  45. long GetNumber(const char *pszValue, long dwDefault = 0);
  46. long DeleteValue(const char *pszValue);
  47. long FlushKey();
  48. VOID MoveToSubKey(const char *pszSubKeyName);
  49. HKEY GetKey() { return _hkey; }
  50. private:
  51. HKEY _hkey;
  52. long _error;
  53. BOOL bhkeyValid;
  54. };
  55. class RegEnumValues
  56. {
  57. public:
  58. RegEnumValues(RegEntry *pRegEntry);
  59. ~RegEnumValues();
  60. long Next();
  61. char * GetName() {return pchName;}
  62. DWORD GetType() {return dwType;}
  63. LPBYTE GetData() {return pbValue;}
  64. DWORD GetDataLength() {return dwDataLength;}
  65. private:
  66. RegEntry * pRegEntry;
  67. DWORD iEnum;
  68. DWORD cEntries;
  69. CHAR * pchName;
  70. LPBYTE pbValue;
  71. DWORD dwType;
  72. DWORD dwDataLength;
  73. DWORD cMaxValueName;
  74. DWORD cMaxData;
  75. LONG _error;
  76. };
  77. class NPMachineEntries : public RegEntry
  78. {
  79. public:
  80. NPMachineEntries(const char *pszSectionName);
  81. const char * GetSectionName() { return pszSectionName; }
  82. private:
  83. const char * pszSectionName; // Warning: data not copied into object.
  84. };
  85. #endif