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.

178 lines
3.9 KiB

  1. //+================================================================
  2. //
  3. // File: CMoniker.hxx
  4. //
  5. // Purpose: This file declares the CMoniker class.
  6. // This class manages a file moniker.
  7. //
  8. //+================================================================
  9. #ifndef _C_MONIKER_HXX_
  10. #define _C_MONIKER_HXX_
  11. // --------
  12. // Includes
  13. // --------
  14. #include "CDir.hxx"
  15. // --------
  16. // CMoniker
  17. // --------
  18. class CMoniker
  19. {
  20. // (De)Construction
  21. public:
  22. CMoniker();
  23. ~CMoniker();
  24. // Public member routines.
  25. public:
  26. BOOL GetTemporaryStorageTime( FILETIME *);
  27. BOOL Initialize( const CDirectory& cDirectoryOriginal,
  28. const CDirectory& cDirectoryFinal );
  29. BOOL CreateFileMonikerEx( DWORD dwTrackFlags = 0L );
  30. BOOL SaveDeleteLoad();
  31. BOOL ComposeWith();
  32. BOOL Reduce( DWORD dwDelay, IMoniker** ppmkReduced = NULL );
  33. BOOL GetDisplayName( WCHAR * wszDisplayName, IMoniker* pmnkCaller = NULL );
  34. BOOL GetTimeOfLastChange( FILETIME *ft );
  35. BOOL BindToStorage();
  36. BOOL BindToObject();
  37. BOOL CreateTemporaryStorage();
  38. BOOL RenameTemporaryStorage();
  39. BOOL DeleteTemporaryStorage();
  40. const WCHAR * GetTemporaryStorageName() const;
  41. IBindCtx* GetBindCtx() const;
  42. BOOL TouchTemporaryStorage();
  43. HRESULT GetHResult() const;
  44. void SuppressErrorMessages( BOOL bSuppress );
  45. BOOL InitializeBindContext( );
  46. // Private member routines.
  47. private:
  48. BOOL CreateLinkTrackingRegistryKey();
  49. BOOL OpenLinkTrackingRegistryKey();
  50. BOOL CloseLinkTrackingRegistryKey();
  51. void DisplayErrors( BOOL bSuccess, WCHAR * wszFunctionName ) const;
  52. // Private data members
  53. private:
  54. WCHAR m_wszSystemTempPath[ MAX_PATH + sizeof( L'\0' ) ];
  55. WCHAR m_wszTemporaryStorage[ MAX_PATH + sizeof( L'\0' ) ];
  56. IMoniker* m_pIMoniker;
  57. IBindCtx* m_pIBindCtx;
  58. IStorage* m_pIStorage;
  59. WCHAR m_wszErrorMessage[ 100 ];
  60. DWORD m_dwTrackFlags;
  61. BOOL m_bSuppressErrorMessages;
  62. const CDirectory* m_pcDirectoryOriginal;
  63. const CDirectory* m_pcDirectoryFinal;
  64. // The following key, along with being a usable handle, is a flag
  65. // which indicates if we need to restore the data in the registry.
  66. HKEY m_hkeyLinkTracking;
  67. // Note that m_hr is used for more than just HRESULTs, sometimes
  68. // it is used for other errors as well.
  69. HRESULT m_hr;
  70. };
  71. // --------------
  72. // Inline Members
  73. // --------------
  74. #define OUTFILE stdout
  75. // CMoniker::DisplayErrors
  76. inline void CMoniker::DisplayErrors( BOOL bSuccess, WCHAR * wszFunctionName ) const
  77. {
  78. if( !bSuccess
  79. &&
  80. !m_bSuppressErrorMessages
  81. )
  82. {
  83. fwprintf( OUTFILE, L"Error in %s (%08x)\n %s\n",
  84. wszFunctionName, m_hr, m_wszErrorMessage );
  85. }
  86. }
  87. // CMoniker::GetTemporaryStorage
  88. inline const WCHAR * CMoniker::GetTemporaryStorageName() const
  89. {
  90. return m_wszTemporaryStorage;
  91. }
  92. // CMoniker::GetBindCtx
  93. inline IBindCtx* CMoniker::GetBindCtx() const
  94. {
  95. return( m_pIBindCtx );
  96. }
  97. // CMoniker::GetHResult
  98. inline HRESULT CMoniker::GetHResult() const
  99. {
  100. return( m_hr );
  101. }
  102. // CMoniker::SuppressErrorMessages
  103. inline void CMoniker::SuppressErrorMessages( BOOL bSuppress )
  104. {
  105. // Normalize to TRUE or FALSE
  106. m_bSuppressErrorMessages = bSuppress ? TRUE : FALSE;
  107. }
  108. // ------
  109. // Macros
  110. // ------
  111. #define DEFAULT_TRACK_FLAGS ( TRACK_LOCALONLY )
  112. #define EXIT_ON_FAILED( error ) if( FAILED( m_hr )) \
  113. {\
  114. wcscpy( m_wszErrorMessage, ##error );\
  115. goto Exit;\
  116. }
  117. #undef EXIT
  118. #define EXIT( error ) \
  119. {\
  120. wcscpy( m_wszErrorMessage, ##error );\
  121. goto Exit;\
  122. }
  123. #endif // _C_MONIKER_HXX_