summaryrefslogtreecommitdiffstats
path: root/private/oleutest/cfmex/cmoniker.hxx
blob: 7d9e1ada0ca8196986ccc37f81026bbe7542fb48 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178


//+================================================================
//
//  File:       CMoniker.hxx
//
//  Purpose:    This file declares the CMoniker class.
//              This class manages a file moniker.
//
//+================================================================


#ifndef _C_MONIKER_HXX_
#define _C_MONIKER_HXX_


//  --------
//  Includes
//  --------

#include "CDir.hxx"

//  --------
//  CMoniker
//  --------

class CMoniker
{

// (De)Construction

public:

    CMoniker();
    ~CMoniker();

// Public member routines.

public:

    BOOL GetTemporaryStorageTime( FILETIME *);
    BOOL Initialize( const CDirectory& cDirectoryOriginal,
                     const CDirectory& cDirectoryFinal );
    BOOL CreateFileMonikerEx( DWORD dwTrackFlags = 0L );
    BOOL SaveDeleteLoad();
    BOOL ComposeWith();
    BOOL Reduce( DWORD dwDelay, IMoniker** ppmkReduced = NULL );
    BOOL GetDisplayName( WCHAR * wszDisplayName, IMoniker* pmnkCaller = NULL );
    BOOL GetTimeOfLastChange( FILETIME *ft );
    BOOL BindToStorage();
    BOOL BindToObject();

    BOOL CreateTemporaryStorage();
    BOOL RenameTemporaryStorage();
    BOOL DeleteTemporaryStorage();

    const WCHAR * GetTemporaryStorageName() const;
    IBindCtx* GetBindCtx() const;
    BOOL TouchTemporaryStorage();
    HRESULT GetHResult() const;
    void SuppressErrorMessages( BOOL bSuppress );
    BOOL InitializeBindContext( );


// Private member routines.

private:

    BOOL CreateLinkTrackingRegistryKey();
    BOOL OpenLinkTrackingRegistryKey();
    BOOL CloseLinkTrackingRegistryKey();
    void DisplayErrors( BOOL bSuccess, WCHAR * wszFunctionName ) const;


// Private data members

private:

    WCHAR m_wszSystemTempPath[ MAX_PATH + sizeof( L'\0' ) ];
    WCHAR m_wszTemporaryStorage[ MAX_PATH + sizeof( L'\0' ) ];

    IMoniker* m_pIMoniker;
    IBindCtx* m_pIBindCtx;
    IStorage* m_pIStorage;

    WCHAR  m_wszErrorMessage[ 100 ];
    DWORD  m_dwTrackFlags;
    BOOL   m_bSuppressErrorMessages;

    const CDirectory* m_pcDirectoryOriginal;
    const CDirectory* m_pcDirectoryFinal;

    // The following key, along with being a usable handle, is a flag
    // which indicates if we need to restore the data in the registry.

    HKEY m_hkeyLinkTracking;


    // Note that m_hr is used for more than just HRESULTs, sometimes
    // it is used for other errors as well.

    HRESULT m_hr;

};


//  --------------
//  Inline Members
//  --------------

#define OUTFILE     stdout

// CMoniker::DisplayErrors

inline void CMoniker::DisplayErrors( BOOL bSuccess, WCHAR * wszFunctionName ) const
{
    if( !bSuccess
        &&
        !m_bSuppressErrorMessages
      )
    {
        fwprintf( OUTFILE, L"Error in %s (%08x)\n   %s\n",
                  wszFunctionName, m_hr, m_wszErrorMessage );
    }
}

// CMoniker::GetTemporaryStorage

inline const WCHAR * CMoniker::GetTemporaryStorageName() const
{
    return m_wszTemporaryStorage;
}

// CMoniker::GetBindCtx

inline IBindCtx* CMoniker::GetBindCtx() const
{
    return( m_pIBindCtx );
}

// CMoniker::GetHResult

inline HRESULT CMoniker::GetHResult() const
{
    return( m_hr );
}

// CMoniker::SuppressErrorMessages

inline void CMoniker::SuppressErrorMessages( BOOL bSuppress )
{
    // Normalize to TRUE or FALSE

    m_bSuppressErrorMessages = bSuppress ? TRUE : FALSE;
}


//  ------
//  Macros
//  ------

#define DEFAULT_TRACK_FLAGS         ( TRACK_LOCALONLY )

#define EXIT_ON_FAILED( error )     if( FAILED( m_hr )) \
                                    {\
                                       wcscpy( m_wszErrorMessage, ##error );\
                                       goto Exit;\
                                    }

#undef EXIT
#define EXIT( error )               \
                                    {\
                                       wcscpy( m_wszErrorMessage, ##error );\
                                       goto Exit;\
                                    }


#endif // _C_MONIKER_HXX_