-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscMaster.cpp
More file actions
106 lines (80 loc) · 2.8 KB
/
DiscMaster.cpp
File metadata and controls
106 lines (80 loc) · 2.8 KB
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
// DiscMaster.cpp : implementation file
//
#include "pch.h"
#include "CdBurnApp.h"
#include "DiscMaster.h"
bool DiscMaster::initialize() {
if (m_discMaster == nullptr)
{
this->m_result = CoCreateInstance(__uuidof(MsftDiscMaster2), NULL, CLSCTX_ALL, __uuidof(IDiscMaster2),
reinterpret_cast<void**>(&m_discMaster)); //Create instance of IDiscMaster2 interface
if (!SUCCEEDED(this->m_result))
{
m_errorMessage.Format(_T("Couldn't initialize the IDiscMaster2 - Error:0x%08x"), m_result); //create a error message that show hresult code of error in hex format
return false;
}
}
//check is there any device use the interface
VARIANT_BOOL isSupported = VARIANT_FALSE;
m_result = m_discMaster->get_IsSupportedEnvironment(&isSupported);
if (!SUCCEEDED(m_result))
{
m_errorMessage.Format(_T("get_IsSupportedEnvironment error IDiscMaster2 - Error:0x%08x"), m_result); //create a error message that show hresult code of error in hex format
return false;
}
//check the media is supported or not
if (isSupported == VARIANT_FALSE)
{
m_errorMessage = _T("There were no writable devices detected!");
return false;
}
return true;
}
CString DiscMaster::getId(long index)
{
BSTR uniqueID = NULL;
m_result = m_discMaster->get_Item(index, &uniqueID);
if (FAILED(m_result))
{
m_errorMessage.Format(_T("IDiscMaster2->get_Item(%d) failed! - Error:0x%08x"),
index, m_result);
return _T("");
}
return uniqueID;
}
bool DiscMaster::enumerateDiscMasters() {
UINT iCounter = 0;
LONG lValue = 0;
BSTR bstrDeviceName;
do {
// Get the number of drives
m_result = m_discMaster->get_Count(&lValue);
if (SUCCEEDED(m_result)) {
m_errorMessage.Format(_T("\nTotal number of drives = %d\n"), lValue);
}
// Print all the optical drives attached to the system
if (SUCCEEDED(m_result)) {
for (LONG iCount = 0; iCount < lValue; iCount++) {
m_result = m_discMaster->get_Item(iCount, &bstrDeviceName);
//_tprintf(TEXT("\nUnique identifier of the disc device associated with index %d is: %s\n"), iCount, bstrDeviceName);
}
}
iCounter++;
} while (iCounter < 1);
return true;
}
long DiscMaster::getNumberOfDevices() {
if (m_discMaster == NULL)
{
return 0;
}
long total_number = 0;
m_result = m_discMaster->get_Count(&total_number);
if (FAILED(m_result))
{
m_errorMessage.Format(_T("get_Count error IDiscMaster2 - Error:0x%08x"), m_result);
return 0;
}
return total_number;
}
// DiscMaster message handlers