Hi,
From past 1 week i stuck on this please help me i am attaching code.
bool DVDBurner::Burner()
{
m_hResult = CoCreateInstance(__uuidof(MsftDiscFormat2Data), NULL, CLSCTX_INPROC_SERVER,
__uuidof(IDiscFormat2Data), (void**)&m_discFormatData);
if (!SUCCEEDED(m_hResult))
{
qDebug()<<"Unable to Initialize IDiscFormat2Data ";
return false;
}
m_hResult = CoCreateInstance(__uuidof(MsftDiscRecorder2), NULL, CLSCTX_INPROC_SERVER,
__uuidof(IDiscRecorder2), (void**)&m_discRecorder);
if (FAILED(m_hResult))
{
qDebug()<<"Unable to Initialize IDiscRecorder2 Data ";
return false;
}
BSTR bstrDeviceName;
HRESULT hr = S_OK;
BOOL bComInitialised;
UINT iCounter = 0;
LONG lValue = 0;
LONG iCount;
bComInitialised = SUCCEEDED(CoInitializeEx(0, COINIT_MULTITHREADED));
// Create an object of IDiscMaster2
if (SUCCEEDED(hr)){
CoCreateInstance(
CLSID_MsftDiscMaster2,
NULL, CLSCTX_ALL,
IID_PPV_ARGS(&discMaster)
);
if(FAILED(hr)){
qDebug()<<"\nUnsuccessful in creating an instance of CLSID_MsftDiscMaster2.\n\nError returned: 0x%x\n"<<hr;
return 0; }
}
/////////////////////////// Get the number of drives///////////////////////////////
if (SUCCEEDED(hr)){
hr = discMaster->get_Count(&lValue);
if (SUCCEEDED(hr)){
printf("lValue %d\n\n",lValue);
} }
////////////////////////// Print all the optical drives attached to the system////
if (SUCCEEDED(hr)){
for(iCount = 0; iCount < lValue; iCount++) {
hr = discMaster->get_Item(iCount, &bstrDeviceName);
qDebug()<<"\nUnique identifier of the disc device associated with index"<< iCount<< bstrDeviceName;
} }
m_hResult = m_discRecorder->InitializeDiscRecorder(bstrDeviceName);
if (!SUCCEEDED(m_hResult))
{
qDebug()<<"IDiscFormat2Data->InitializeDiscRecorder Failed ";
return false;
}
LPCWSTR pszFile=L"D:\\Test\\output.txt";
ULONGLONG mediaSize = 0;
mediaSize=GetSizeOnDisc(pszFile);
IStream* dataStream = NULL;
if (dataStream == NULL)
{
SHCreateStreamOnFileEx(pszFile,
STGM_READ|STGM_SHARE_DENY_NONE|STGM_DELETEONRELEASE,
FILE_ATTRIBUTE_NORMAL,
FALSE,NULL, &dataStream);
}
m_hResult = m_discFormatData->put_Recorder(GetInterface());
if (!SUCCEEDED(m_hResult))
{ qDebug()<<"IDiscFormat2Data->put_Recorder Failed ";return false;}
char *ansistr = "DVDBurner";
int a = lstrlenA(ansistr);
BSTR unicodestr = SysAllocStringLen(NULL, a);
::MultiByteToWideChar(CP_ACP, 0, ansistr, a, unicodestr, a);
m_hResult = m_discFormatData->put_ClientName(unicodestr);
if (FAILED(m_hResult)){qDebug()<<"Unable to put_ClientName(buf_bstr)";return false;}
m_hResult = m_discFormatData->Write(dataStream); // Here i am getting error 0xc0aa0403
if (FAILED(m_hResult)){printf("Unable to m_discFormatData- >Write::::Error:0x%08x",m_hResult); return false;}
discMaster->Release();
CoUninitialize();
bComInitialised = FALSE;
return 0;
}
ULONGLONG DVDBurner::GetSizeOnDisc(LPCWSTR pszFile)
{
CFileStatus status;
if (CFile::GetStatus(pszFile, status))
{
if (status.m_size > 0) { return ((status.m_size / SECTOR_SIZE) + 1) * SECTOR_SIZE; }
}
return 0;
}