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.

Registry.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // -=- Registry.h
  19. // C++ wrappers around the Win32 Registry APIs
  20. #ifndef __RFB_WIN32_REGISTRY_H__
  21. #define __RFB_WIN32_REGISTRY_H__
  22. #include <windows.h>
  23. #include <rfb_win32/Security.h>
  24. #include <rfb/util.h>
  25. namespace rfb {
  26. namespace win32 {
  27. class RegKey {
  28. public:
  29. // No key open
  30. RegKey();
  31. // Duplicate the specified existing key
  32. RegKey(const HKEY k);
  33. RegKey(const RegKey& k);
  34. // Calls close() internally
  35. ~RegKey();
  36. void setHKEY(HKEY key, bool freeKey);
  37. private:
  38. RegKey& operator=(const RegKey& k);
  39. HKEY& operator=(const HKEY& k);
  40. public:
  41. // Returns true if key was created, false if already existed
  42. bool createKey(const RegKey& root, const TCHAR* name);
  43. // Opens key if it exists, or raises an exception if not
  44. void openKey(const RegKey& root, const TCHAR* name, bool readOnly=false);
  45. // Set the (discretionary) access control list for the key
  46. void setDACL(const PACL acl, bool inheritFromParent=true);
  47. // Closes current key, if required
  48. void close();
  49. // Delete a subkey/value
  50. void deleteKey(const TCHAR* name) const;
  51. void deleteValue(const TCHAR* name) const;
  52. // Block waiting for a registry change, OR return immediately and notify the
  53. // event when there is a change, if specified
  54. void awaitChange(bool watchSubTree, DWORD filter, HANDLE event=0) const;
  55. void setExpandString(const TCHAR* valname, const TCHAR* s) const;
  56. void setString(const TCHAR* valname, const TCHAR* s) const;
  57. void setBinary(const TCHAR* valname, const void* data, size_t length) const;
  58. void setInt(const TCHAR* valname, int i) const;
  59. void setBool(const TCHAR* valname, bool b) const;
  60. TCHAR* getString(const TCHAR* valname) const;
  61. TCHAR* getString(const TCHAR* valname, const TCHAR* def) const;
  62. void getBinary(const TCHAR* valname, void** data, size_t* length) const;
  63. void getBinary(const TCHAR* valname, void** data, size_t* length, void* def, size_t deflength) const;
  64. int getInt(const TCHAR* valname) const;
  65. int getInt(const TCHAR* valname, int def) const;
  66. bool getBool(const TCHAR* valname) const;
  67. bool getBool(const TCHAR* valname, bool def) const;
  68. TCHAR* getRepresentation(const TCHAR* valname) const;
  69. bool isValue(const TCHAR* valname) const;
  70. // Get the name of value/key number "i"
  71. // If there are fewer than "i" values then return 0
  72. // NAME IS OWNED BY RegKey OBJECT!
  73. const TCHAR* getValueName(int i);
  74. const TCHAR* getKeyName(int i);
  75. operator HKEY() const;
  76. protected:
  77. HKEY key;
  78. bool freeKey;
  79. TCharArray valueName;
  80. DWORD valueNameBufLen;
  81. };
  82. };
  83. };
  84. #endif // __RFB_WIN32_REG_CONFIG_H__