CreateRedirectionDC VC++ Example
void CEPrintDemoView::OnCreateRedirectionDC()
{
IEpnBatchPrinterInfo * pBatchPrinterInfo;
IEpnExtraDcOptions * pExtraDcOptions;
IEPrint * pLeadPrnt;
IEpnPrinterList * pPrintersList;
HRESULT hr;
long hDC = NULL;
hr = ::CoCreateInstance(CLSID_EPrint, NULL, CLSCTX_ALL, IID_IEPrint, (void**) &pLeadPrnt);
if(FAILED(hr))
return;
hr = ::CoCreateInstance(CLSID_EpnBatchPrinterInfo, NULL, CLSCTX_ALL, IID_IEpnBatchPrinterInfo, (void**) &pBatchPrinterInfo);
if(FAILED(hr))
return;
hr = ::CoCreateInstance(CLSID_EpnExtraDcOptions, NULL, CLSCTX_ALL, IID_IEpnExtraDcOptions, (void**) &pExtraDcOptions);
if(FAILED(hr))
return;
hr = ::CoCreateInstance(CLSID_EpnPrinterList, NULL, CLSCTX_ALL, IID_IEpnPrinterList, (void**) &pPrintersList);
if(FAILED(hr))
return;
if(pLeadPrnt-> IsSupportLocked (SUPPORT_OEM))
pLeadPrnt->UnlockSupport (SUPPORT_OEM, OEM_KEY);
pBatchPrinterInfo->PrinterName = "";
//ePrint.GetDefaultEnhancedOptions BatchPrinterInfo.EnhancedOptions
pBatchPrinterInfo->Flags = VALID_ENHANCED_OPTIONS;
pPrintersList->AddPrinter (pBatchPrinterInfo);
hDC = pLeadPrnt->CreateRedirectionDC (TEST_PRINTER_NAME, NULL, pPrintersList, NULL);
if(hDC)
{
short nRet;
_bstr_t bstr(" file test ");
nRet = pLeadPrnt->StartDoc (hDC, bstr);
if(nRet == 0)
{
nRet = pLeadPrnt->StartPage (hDC);
if(nRet == 0)
{
PlayGDICommands((HDC)hDC);
nRet = pLeadPrnt->EndPage (hDC);
}
nRet = pLeadPrnt->EndDoc (hDC);
}
pLeadPrnt->DeleteDC ((long)hDC);
}
if(pExtraDcOptions)
{
pExtraDcOptions->Release();
pExtraDcOptions = NULL;
}
if(pBatchPrinterInfo)
{
pBatchPrinterInfo->Release();
pBatchPrinterInfo = NULL;
}
if(pPrintersList)
{
pPrintersList->Release();
pPrintersList = NULL;
}
if(pLeadPrnt)
{
pLeadPrnt->Release();
pLeadPrnt = NULL;
}
}