-
Notifications
You must be signed in to change notification settings - Fork 4
/
DiscFormatData.cpp
281 lines (248 loc) · 6.85 KB
/
DiscFormatData.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
///////////////////////////////////////////////////////////////////////
// DiscFormatData.cpp
//
// Wrapper for IDiscFormat2Data Interface
//
// Written by Eric Haddan
//
#include "StdAfx.h"
#include "DiscFormatData.h"
#include "DiscRecorder.h"
#include "DiscFormatDataEvent.h"
CDiscFormatData::CDiscFormatData(void)
: m_discFormatData(NULL)
, m_mediaTypesArray(NULL)
, m_hResult(0)
// , m_hNotificationWnd(NULL)
, m_closeMedia(true)
{
}
CDiscFormatData::~CDiscFormatData(void)
{
if (m_discFormatData != NULL)
{
m_discFormatData->Release();
m_discFormatData = NULL;
}
}
///////////////////////////////////////////////////////////////////////
//
// CDiscFormatData::Initialize()
//
// Description:
// Creates and initializes the IDiscFormat2Data interface
//
bool CDiscFormatData::Initialize(CDiscRecorder* pDiscRecorder, const CString& clientName)
{
ASSERT(m_discFormatData == NULL);
ASSERT(pDiscRecorder != NULL);
if (pDiscRecorder == NULL)
{
m_errorMessage = _T("Error - CDiscFormatData::Initialize - pDiscRecorder is NULL");
return false;
}
//
// Initialize the IDiscFormat2Data Interface
//
m_hResult = CoCreateInstance(__uuidof(MsftDiscFormat2Data), NULL, CLSCTX_INPROC_SERVER,
__uuidof(IDiscFormat2Data), (void**)&m_discFormatData);
if (!SUCCEEDED(m_hResult))
{
m_errorMessage.Format(_T("Unable to Initialize IDiscFormat2Data - Error:0x%08x"), m_hResult);
return false;
}
//
// Setup the Disc Format Information
//
m_hResult = m_discFormatData->get_SupportedMediaTypes(&m_mediaTypesArray); // 获取本系统内所有光驱支持的媒体格式 两个光驱则是罗列两个光驱的所有媒体格式
if (!SUCCEEDED(m_hResult))
{
m_errorMessage.Format(_T("IDiscFormat2Data->get_SupportedMediaTypes Failed - Error:0x%08x"), m_hResult);
return false;
}
//SAFEARRAY* pSafeArray;
m_hResult = pDiscRecorder->GetInterface()->get_SupportedProfiles(&m_mediaTypesArray); // 此时是获取一个光驱的支持媒体格式
if(!SUCCEEDED(m_hResult))
{
m_errorMessage.Format(_T("IDiscRecorder2->get_SupportedProfiles Failed - Error:0x%08x"), m_hResult);
return false;
}
VARIANT_BOOL isSupported = VARIANT_FALSE;
m_hResult = m_discFormatData->IsRecorderSupported(pDiscRecorder->GetInterface(), &isSupported); // 具体含义不清楚,只知道,如果是支持刻录的,将返回Supported,否则不支持
if (isSupported == VARIANT_FALSE)
{
m_errorMessage = _T("Recorder not supported\r\n"); // maybe 检索刻录机是否支持刻录 数据流 形式的数据
return false;
}
m_hResult = m_discFormatData->put_Recorder(pDiscRecorder->GetInterface());
if (!SUCCEEDED(m_hResult))
{
m_errorMessage.Format(_T("IDiscFormat2Data->put_Recorder Failed - Error:0x%08x"), m_hResult);
DWORD dwLastErr = GetLastError();
return false;
}
m_hResult = m_discFormatData->put_ClientName(clientName.AllocSysString());
if (!SUCCEEDED(m_hResult))
{
m_errorMessage.Format(_T("IDiscFormat2Data->put_ClientName Failed - Error:0x%08x"), m_hResult);
return false;
}
return true;
}
ULONG CDiscFormatData::GetTotalSupportedMediaTypes()
{
if (m_mediaTypesArray == NULL)
return 0;
return m_mediaTypesArray->rgsabound[0].cElements;
}
int CDiscFormatData::GetSupportedMediaType(ULONG index)
{
ASSERT(index < GetTotalSupportedMediaTypes());
if (index < GetTotalSupportedMediaTypes())
{
if (m_mediaTypesArray)
{
return ((VARIANT*)(m_mediaTypesArray->pvData))[index].intVal;
}
}
return 0;
}
bool CDiscFormatData::Burn(HWND hNotificationWnd, IStream* streamData)
{
if (m_discFormatData == NULL)
return false;
// if (hNotificationWnd == NULL)
// return false;
if (streamData == NULL)
return false;
m_streamData = streamData;
// m_hNotificationWnd = hNotificationWnd;
// Create the event sink
CDiscFormatDataEvent* eventSink = CDiscFormatDataEvent::CreateEventSink();
if (eventSink == NULL)
{
m_errorMessage = _T("Unable to create event sink");
return false;
}
if (!eventSink->ConnectDiscFormatData(this))
{
m_errorMessage = _T("Unable to connect event sink with interface");
return false;
}
// eventSink->SetHwnd(m_hNotificationWnd);
// m_discFormatData->put_ForceMediaToBeClosed( VARIANT_TRUE );
m_hResult = m_discFormatData->Write(m_streamData);
delete eventSink;
if (SUCCEEDED(m_hResult))
{
return true;
}
m_errorMessage = GetWriteErrorMsg(m_hResult);
m_errorMessage.Format(_T("IDiscFormat2Data->Write Failed! Error:0x%08x"),
m_hResult);
return false;
}
CString CDiscFormatData::GetWriteErrorMsg(HRESULT hr)
{
CString cstrWriteError;
switch(hr)
{
case 0xC0AA020D:
cstrWriteError = _T("超时");
break;
case 0xC0AA02FF:
cstrWriteError = _T("异常或者数据无效");
break;
case 0xC0AA0204:
cstrWriteError = _T("光盘放颠倒了");
break;
case 0xC0AA0205:
cstrWriteError = _T("准备中,稍后可能需要继续调用Write函数");
break;
case 0xC0AA0202:
cstrWriteError = _T("光驱中无光盘");
break;
case 0xC0AA0206:
cstrWriteError = _T("media正在格式化,请稍等");
break;
case 0xC0AA0207:
cstrWriteError = _T("光驱可能已经长时间工作,现在需要停止工作一会");
break;
case 0xC0AA0203:
cstrWriteError = _T("光盘不兼容或者未知的物理格式");
break;
case 0xC0AA0201:
cstrWriteError = _T("光驱要求的页模式,应用程序未提供");
break;
case 0xC0AA0208:
cstrWriteError = _T("模式页不支持");
break;
case 0xC0AA0209:
cstrWriteError = _T("光盘写保护");
break;
case 0xC0AA020F:
cstrWriteError = _T("写入的速度不匹配");
break;
case 6:
cstrWriteError = _T("句柄无效");
break;
case 55:
cstrWriteError = _T("网络异常或者光驱被卸载");
break;
case 0xC0AA0210:
cstrWriteError = _T("光驱正在被其他的写入独占"); //
break;
case 0xC0AA0301:
cstrWriteError = _T("光驱报告异常");
break;
case 0xC0AA0003:
cstrWriteError = _T("写入动作没有指定光驱");
break;
case 0x00AA0005:
cstrWriteError = _T("要求的旋转时刻录,光驱不支持");
break;
case 0x00AA0004:
cstrWriteError = _T("要求的刻录速度光驱不支持,光驱已自行调整刻录速度");
break;
case 0x00AA0006:
cstrWriteError = _T("要求的旋转刻录和刻录速度不支持,光驱已经自行匹配");
break;
case 0xC0AA0407:
cstrWriteError = _T("光驱不支持光盘的格式");
break;
case 0xC0AA0002:
cstrWriteError = _T("操作取消");
break;
case 0xC0AA0400:
cstrWriteError = _T("另一个写入操作与此操作冲突"); //
break;
case 0xC0AA0403:
cstrWriteError = _T("提供的IStream大小无效.The size must be a multiple of the sector size, 2048.");
break;
case 0x80070057:
cstrWriteError = _T("一个或多个操作无效");
break;
case 0x80004003:
cstrWriteError = _T("指针无效");
break;
case 0x80004005:
cstrWriteError = _T("未知的失败");
break;
case 0x8007000E:
cstrWriteError = _T("内存不足");
break;
case 0x80004001:
cstrWriteError = _T("未知");
break;
case 0xC0AA0300:
cstrWriteError = _T("The write failed because the drive did not receive data quickly enough to continue writing");
break;
case 0xC0AA020E:
cstrWriteError = _T("DVD设备未找到");
break;
}
CString strTemp;
strTemp .Format(_T(" 错误号:0x%x,"),hr);
cstrWriteError += strTemp;
return cstrWriteError;
}