aduiRegistryAccess.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Autodesk, Inc. All rights reserved.
  4. //
  5. // Use of this software is subject to the terms of the Autodesk license
  6. // agreement provided at the time of installation or download, or which
  7. // otherwise accompanies this software in either electronic or hard copy form.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef _aduiRegistryAccess_h
  11. #define _aduiRegistryAccess_h
  12. #pragma pack (push, 8)
  13. #if _MSC_VER >= 1000
  14. #pragma once
  15. #endif // _MSC_VER >= 1000
  16. // This file is also built as part of accore.dll separately from the rest of
  17. // AdUi. To do so, we can only use a part of MFC, so a little tweaking is
  18. // needed.
  19. //
  20. #ifdef ACUTIL_INTERNAL
  21. #include <tchar.h>
  22. #include <afx.h>
  23. #ifdef ADUI_PORT
  24. #undef ADUI_PORT
  25. #endif
  26. #ifdef ACCORE_BUILD
  27. #define ADUI_PORT __declspec(dllexport)
  28. #else
  29. #define ADUI_PORT
  30. #endif
  31. #endif
  32. #ifndef ADUI_PORT
  33. #define ADUI_PORT
  34. #endif
  35. //////////////////////////////////////////////////////////////////////////////
  36. // Note: These classes are for INTERNAL USE ONLY and may be slated for removal.
  37. class ADUI_PORT CAdUiRegistryAccess // pure virtual class?
  38. {
  39. public:
  40. // Construction/destruction:
  41. CAdUiRegistryAccess();
  42. CAdUiRegistryAccess(HKEY hKey,const CString& sSubkey); // Implicitly opens
  43. virtual ~CAdUiRegistryAccess();
  44. // Allows this class to be used anywhere an HKEY is valid...
  45. operator HKEY() const;
  46. // Access control: Opens to (another) key.
  47. virtual BOOL Open(HKEY hKey,const CString &sSubkey);
  48. virtual void Close();
  49. BOOL IsOpen();
  50. // Enumeration mechanism:
  51. BOOL EnumKeyNames(DWORD dwEntryIndex,CString& sKeyName);
  52. BOOL EnumValueNames(DWORD dwEntryIndex,CString& sValueName,LPDWORD lpdwType = NULL); // throw CMemoryException*;
  53. // Note: 1) Enumerate from 0 up to end, or from end back to 0.
  54. // 2) do not alter the key or value being enumerated during the enumeration
  55. // (These are caveats presented by the underlying API calls...)
  56. // returns REG_... types, or REG_NONE if the key doesn't exist.
  57. DWORD ValueType(const CString& sValueName,LPDWORD lpdwSize = NULL);
  58. // GetAccess:
  59. CString GetString(const CString& sValueName); // throw CMemoryException*;
  60. // NOTE that GetDWord returns 0 on failure! It also returns 0
  61. // if the value is indeed 0. BEWARE USING THIS FUNCTION!
  62. DWORD GetDWord(const CString& sValueName);
  63. // Note: If the value doesn't exist, dwDefault will be returned instead of 0.
  64. DWORD GetDWordWithDefaultValue(const CString &sValueName, DWORD dwDefault);
  65. BOOL GetBinary(const CString& sValueName, LPBYTE pbData, DWORD& dwSize);
  66. protected:
  67. // Derivation for write permission can override this:
  68. void CommonConstruction();
  69. HKEY m_hKey;
  70. CString m_sSubkey;
  71. };
  72. class ADUI_PORT CAdUiRegistryWriteAccess: public CAdUiRegistryAccess
  73. // Adds write capabilities to the registry access object;
  74. //
  75. // Remember: do not write to keys or values during
  76. // an enumeration loop... (Registry API limitation)
  77. {
  78. public:
  79. // Construction/destruction:
  80. CAdUiRegistryWriteAccess();
  81. CAdUiRegistryWriteAccess(HKEY hKey,const CString& sSubkey);
  82. virtual ~CAdUiRegistryWriteAccess();
  83. virtual BOOL Open(HKEY hKey,const CString& sSubkey);
  84. BOOL SetString(const CString& cValueName, const CString& sValue); // throw CMemoryException*;
  85. BOOL SetDWord(const CString& sValueName, DWORD dwValue);
  86. BOOL SetBinary(const CString& sValueName, const BYTE* pbData, DWORD dwLen);
  87. };
  88. class ADUI_PORT CAdUiRegistryDeleteAccess: public CAdUiRegistryWriteAccess
  89. //
  90. // Adds deletion capabilities to the registry access object.
  91. // Deliberately left as a derived class (rather than folded
  92. // into the Write class, because of the potential harm
  93. // possible by accidental use.
  94. //
  95. // Remember: do not delete or write to keys or values during
  96. // an enumeration loop... (Registry API limitation)
  97. //
  98. {
  99. public:
  100. CAdUiRegistryDeleteAccess();
  101. CAdUiRegistryDeleteAccess(HKEY hKey,const CString& sSubkey);
  102. virtual ~CAdUiRegistryDeleteAccess();
  103. // Deletes a specific value
  104. BOOL DeleteValue(const CString& sValueName);
  105. // Deletes all values under this key
  106. BOOL DeleteAllValues();
  107. // Deletes a specific subkey; (note: in Win95, this is the same as below)
  108. BOOL DeleteKey(const CString& sKeyName);
  109. // Deletes a specific subkey, and all sub-keys beneath it (needed in NT)
  110. BOOL DeleteKeyAndSubkeys(const CString& sKeyName); // recursive
  111. // Deletes all subkeys in the current key; like "del *.* /s" is to DOS (dangerous!)
  112. BOOL DeleteAllKeys(); // recursive
  113. };
  114. //////////////////////////////////////////////////////////////////////////////
  115. //{{AFX_INSERT_LOCATION}}
  116. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  117. #pragma pack (pop)
  118. #endif
  119. //////////////////////////////////////////////////////////////////////////////