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.

115 lines
4.3 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: creg.h
  6. * Content: definition of the CRegistry class
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/16/99 rodtoll Created
  12. * 08/18/99 rodtoll Added Register/UnRegister that can be used to
  13. * allow COM objects to register themselves.
  14. * 08/25/99 rodtoll Updated to provide read/write of binary (blob) data
  15. * 10/07/99 rodtoll Updated to work in Unicode
  16. * 10/27/99 pnewson added Open() call that takes a GUID
  17. * 01/18/00 mjn Added GetMaxKeyLen function
  18. * 01/24/00 mjn Added GetValueSize function
  19. * 04/05/2000 jtk Changed GetVauleSize to GetValueLength and modified to return WCHAR lengths
  20. * 04/21/2000 rodtoll Bug #32889 - Does not run on Win2k on non-admin account
  21. * rodtoll Bug #32952 - Does not run on Win95 GOLD w/o IE4 -- modified
  22. * to allow reads of REG_BINARY when expecting REG_DWORD
  23. * 07/09/2000 rodtoll Added signature bytes
  24. * 08/28/2000 masonb Voice Merge: Modified platform checks to use osind.cpp layer (removed CRegistry::CheckUnicodePlatform)
  25. * 04/13/2001 VanceO Moved granting registry permissions into common, and
  26. * added DeleteValue and EnumValues.
  27. * 06/19/2001 RichGr DX8.0 added special security rights for "everyone" - remove them if
  28. * they exist with new RemoveAllAccessSecurityPermissions() method.
  29. *
  30. ***************************************************************************/
  31. #ifndef __CREGISTRY_H
  32. #define __CREGISTRY_H
  33. // Useful definition
  34. #define MAX_REGISTRY_STRING_SIZE _MAX_PATH+1
  35. #define DPN_KEY_ALL_ACCESS ((KEY_ALL_ACCESS & ~WRITE_DAC) & ~WRITE_OWNER)
  36. #define VSIG_CREGISTRY 'GERV'
  37. #define VSIG_CREGISTRY_FREE 'GER_'
  38. // CRegistry
  39. //
  40. // This class handles reading/writing to the windows registry. Each instance
  41. // of the CRegistry class is attached to a single registry handle, which is
  42. // an open handle to a point in the registry tree.
  43. //
  44. class CRegistry
  45. {
  46. public:
  47. CRegistry();
  48. CRegistry( const CRegistry &registry );
  49. CRegistry( const HKEY branch, LPWSTR pathName, BOOL fReadOnly = TRUE, BOOL create = FALSE );
  50. ~CRegistry();
  51. BOOL EnumKeys( LPWSTR lpwStrName, LPDWORD lpdwStringLen, DWORD index = 0 );
  52. BOOL EnumValues( LPWSTR lpwStrName, LPDWORD lpdwStringLen, DWORD index = 0 );
  53. BOOL Open( const HKEY branch, const LPCWSTR pathName, BOOL fReadOnly = TRUE, BOOL create = FALSE, BOOL fCustomSAM = FALSE, REGSAM samCustom = NULL);
  54. BOOL Open( const HKEY branch, const GUID* lpguid, BOOL fReadOnly = TRUE, BOOL create = FALSE, BOOL fCustomSAM = FALSE, REGSAM samCustom = NULL);
  55. BOOL Close();
  56. BOOL IsOpen() { return m_isOpen; };
  57. BOOL DeleteSubKey( LPCWSTR keyName );
  58. BOOL DeleteSubKey( const GUID *pGuidName );
  59. BOOL DeleteValue( LPCWSTR valueName );
  60. BOOL ReadGUID( LPCWSTR keyName, GUID &guid );
  61. BOOL WriteGUID( LPCWSTR keyName, const GUID &guid );
  62. BOOL WriteString( LPCWSTR keyName, const LPCWSTR lpwstrValue );
  63. BOOL ReadString( LPCWSTR keyName, LPWSTR lpwstrValue, LPDWORD lpdwLength );
  64. BOOL WriteDWORD( LPCWSTR keyName, DWORD value );
  65. BOOL ReadDWORD( LPCWSTR keyName, DWORD &result );
  66. BOOL WriteBOOL( LPCWSTR keyName, BOOL value );
  67. BOOL ReadBOOL( LPCWSTR keyName, BOOL &result );
  68. BOOL ReadBlob( LPCWSTR keyName, LPBYTE lpbBuffer, LPDWORD lpdwSize );
  69. BOOL WriteBlob( LPCWSTR keyName, LPBYTE lpbBuffer, DWORD dwSize );
  70. BOOL GetMaxKeyLen( DWORD &dwMaxKeyLen );
  71. BOOL GetValueLength( const LPCWSTR keyName, DWORD *const pdwValueLength );
  72. BOOL GrantAllAccessSecurityPermissions();
  73. BOOL RemoveAllAccessSecurityPermissions();
  74. static BOOL Register( LPCWSTR lpszProgID, LPCWSTR lpszDesc, LPCWSTR lpszProgName, GUID guidCLSID, LPCWSTR lpszVerIndProgID );
  75. static BOOL UnRegister( GUID guidCLSID );
  76. // Data access functions
  77. operator HKEY() const { return m_regHandle; };
  78. HKEY GetBaseHandle() const { return m_baseHandle; };
  79. HKEY GetHandle() const { return m_regHandle; };
  80. protected:
  81. DWORD m_dwSignature; // Signature
  82. BOOL m_fReadOnly;
  83. BOOL m_isOpen; // BOOL indicating if the object is open
  84. HKEY m_regHandle; // Handle to the registry which is represented by this object
  85. HKEY m_baseHandle; // Handle to the root of the part of the registry
  86. // this object is in. E.g. HKEY_LOCAL_MACHINE
  87. };
  88. #endif