-
Notifications
You must be signed in to change notification settings - Fork 4
/
DiscFormatDataEvent.cpp
226 lines (193 loc) · 6.2 KB
/
DiscFormatDataEvent.cpp
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
///////////////////////////////////////////////////////////////////////
// DiscFormatDataEvent.cpp
//
// Wrapper for DDiscFormat2DataEvents Interface Events
//
// Written by Eric Haddan
//
#include "stdafx.h"
#include "DiscFormatDataEvent.h"
#include "DiscFormatData.h"
// CDiscFormatDataEvent
IMPLEMENT_DYNAMIC(CDiscFormatDataEvent, CCmdTarget)
BEGIN_INTERFACE_MAP(CDiscFormatDataEvent, CCmdTarget)
INTERFACE_PART(CDiscFormatDataEvent, IID_IDispatch, FormatDataEvents)
INTERFACE_PART(CDiscFormatDataEvent, IID_DDiscFormat2DataEvents, FormatDataEvents)
END_INTERFACE_MAP()
CDiscFormatDataEvent::CDiscFormatDataEvent()
: m_ptinfo(NULL)
// , m_hNotifyWnd(NULL)
, m_dwCookie(0)
, m_pUnkSink(0)
, m_pUnkSrc(0)
{
}
CDiscFormatDataEvent::~CDiscFormatDataEvent()
{
if (m_dwCookie && (m_pUnkSrc != NULL) && (m_pUnkSink != NULL))
{
AfxConnectionUnadvise(m_pUnkSrc, IID_DDiscFormat2DataEvents, m_pUnkSink,
TRUE, m_dwCookie);
}
}
BEGIN_MESSAGE_MAP(CDiscFormatDataEvent, CCmdTarget)
END_MESSAGE_MAP()
// CDiscFormatDataEvent message handlers
ULONG FAR EXPORT CDiscFormatDataEvent::XFormatDataEvents::AddRef()
{
METHOD_PROLOGUE(CDiscFormatDataEvent, FormatDataEvents)
return pThis->ExternalAddRef();
}
ULONG FAR EXPORT CDiscFormatDataEvent::XFormatDataEvents::Release()
{
METHOD_PROLOGUE(CDiscFormatDataEvent, FormatDataEvents)
return pThis->ExternalRelease();
}
STDMETHODIMP CDiscFormatDataEvent::XFormatDataEvents::QueryInterface(REFIID riid,
LPVOID FAR* ppvObj)
{
METHOD_PROLOGUE(CDiscFormatDataEvent, FormatDataEvents)
return (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
}
STDMETHODIMP
CDiscFormatDataEvent::XFormatDataEvents::GetTypeInfoCount(UINT FAR* pctinfo)
{
METHOD_PROLOGUE(CDiscFormatDataEvent, FormatDataEvents)
*pctinfo = 1;
return NOERROR;
}
STDMETHODIMP CDiscFormatDataEvent::XFormatDataEvents::GetTypeInfo(
UINT itinfo,
LCID lcid,
ITypeInfo FAR* FAR* pptinfo)
{
METHOD_PROLOGUE(CDiscFormatDataEvent, FormatDataEvents)
*pptinfo = NULL;
if(itinfo != 0)
return ResultFromScode(DISP_E_BADINDEX);
pThis->m_ptinfo->AddRef();
*pptinfo = pThis->m_ptinfo;
return NOERROR;
}
STDMETHODIMP CDiscFormatDataEvent::XFormatDataEvents::GetIDsOfNames(
REFIID riid,
OLECHAR FAR* FAR* rgszNames,
UINT cNames,
LCID lcid,
DISPID FAR* rgdispid)
{
METHOD_PROLOGUE(CDiscFormatDataEvent, FormatDataEvents)
return DispGetIDsOfNames(pThis->m_ptinfo, rgszNames, cNames, rgdispid);
}
STDMETHODIMP CDiscFormatDataEvent::XFormatDataEvents::Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS FAR* pdispparams,
VARIANT FAR* pvarResult,
EXCEPINFO FAR* pexcepinfo,
UINT FAR* puArgErr)
{
METHOD_PROLOGUE(CDiscFormatDataEvent, FormatDataEvents)
return DispInvoke(&pThis->m_xFormatDataEvents, pThis->m_ptinfo,
dispidMember, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
}
///////////////////////////////////////////////////////////////////////
//
// CDiscFormatDataEvent::CreateEventSink
//
// Description:
// Establishes a link between the CDiscFormatData(IDiscFormat2Data)
// and the CDiscFormatDataEvent(DDiscFormat2DataEvents) so
// CDiscFormatDataEvent can receive Update messages
//
CDiscFormatDataEvent* CDiscFormatDataEvent::CreateEventSink()
{
// Create the event sink
CDiscFormatDataEvent* pDiscFormatDataEvent = new CDiscFormatDataEvent();
pDiscFormatDataEvent->EnableAutomation();
pDiscFormatDataEvent->ExternalAddRef();
return pDiscFormatDataEvent;
}
///////////////////////////////////////////////////////////////////////
//
// CDiscFormatDataEvent::ConnectDiscFormatData
//
// Description:
// Establishes a link between the CDiscFormatData(IDiscFormat2Data)
// and the CDiscFormatDataEvent(DDiscFormat2DataEvents) so
// CDiscFormatDataEvent can receive Update messages
//
bool CDiscFormatDataEvent::ConnectDiscFormatData(CDiscFormatData* pDiscFormatData)
{
m_pUnkSink = GetIDispatch(FALSE);
m_pUnkSrc = pDiscFormatData->GetInterface();
LPTYPELIB ptlib = NULL;
HRESULT hr = LoadRegTypeLib(LIBID_IMAPILib2,
IMAPILib2_MajorVersion, IMAPILib2_MinorVersion,
LOCALE_SYSTEM_DEFAULT, &ptlib);
if (FAILED(hr))
{
return false;
}
hr = ptlib->GetTypeInfoOfGuid(IID_DDiscFormat2DataEvents, &m_ptinfo);
ptlib->Release();
if (FAILED(hr))
{
return false;
}
BOOL bRet = AfxConnectionAdvise(m_pUnkSrc, IID_DDiscFormat2DataEvents, m_pUnkSink,
TRUE, &m_dwCookie);
if (bRet)
{
return true;
}
return false;
}
///////////////////////////////////////////////////////////////////////
//
// CDiscFormatDataEvent::Update
//
// Description:
// Receives update notifications from IDiscFormat2Data
//
STDMETHODIMP_(HRESULT) CDiscFormatDataEvent::XFormatDataEvents::Update(IDispatch* objectDispatch, IDispatch* progressDispatch)
{
METHOD_PROLOGUE(CDiscFormatDataEvent, FormatDataEvents)
IDiscFormat2DataEventArgs* progress = NULL;
HRESULT hr = progressDispatch->QueryInterface(IID_PPV_ARGS(&progress));
IDiscFormat2Data* discFormatData = NULL;
hr = objectDispatch->QueryInterface(IID_PPV_ARGS(&discFormatData));
IMAPI_FORMAT2_DATA_WRITE_ACTION currentAction = IMAPI_FORMAT2_DATA_WRITE_ACTION_VALIDATING_MEDIA;
hr = progress->get_CurrentAction(¤tAction);
ASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
return S_OK;
}
IMAPI_STATUS imapiStatus = {0};
if ((currentAction == IMAPI_FORMAT2_DATA_WRITE_ACTION_WRITING_DATA) ||
(currentAction == IMAPI_FORMAT2_DATA_WRITE_ACTION_FINALIZATION))
{
progress->get_ElapsedTime(&imapiStatus.elapsedTime);
progress->get_RemainingTime(&imapiStatus.remainingTime);
progress->get_TotalTime(&imapiStatus.totalTime);
if (currentAction == IMAPI_FORMAT2_DATA_WRITE_ACTION_WRITING_DATA)
{
progress->get_StartLba(&imapiStatus.startLba);
progress->get_SectorCount(&imapiStatus.sectorCount);
progress->get_LastReadLba(&imapiStatus.lastReadLba);
progress->get_LastWrittenLba(&imapiStatus.lastWrittenLba);
progress->get_TotalSystemBuffer(&imapiStatus.totalSystemBuffer);
progress->get_UsedSystemBuffer(&imapiStatus.usedSystemBuffer);
progress->get_FreeSystemBuffer(&imapiStatus.freeSystemBuffer);
}
}
// LRESULT ret = ::SendMessage(pThis->m_hNotifyWnd, WM_IMAPI_UPDATE, currentAction, (LPARAM)(LPVOID)&imapiStatus);
// if (ret == RETURN_CANCEL_WRITE)
// {
// discFormatData->CancelWrite();
// }
return S_OK;
}