InstallOEMPrinter VC++ Example

void CEPrintDemoView::OnInstallOEMPrinter()
{
   IEpnPrinterSpecifications * pPrinterSpecifications; 
   IEpnMultiSaveOptions * pMultiSaveOptions; 
   IEpnMailMessageInfo * pMailMessageInfo; 
   IEpnBatchPrinterInfo * pBatchPrinterInfo; 
   IEpnPrinterList * pPrintersList; 
   IEpnOemPrinterInfo * pOemPrinterInfo; 
   IEpnMailConfigurationSettings * pMailConfigurationSettings; 
   IEPrint * pLeadPrnt; 
   HRESULT hr; 
   int nRet = 0; 

   hr = ::CoCreateInstance(CLSID_EPrint, NULL, CLSCTX_ALL, IID_IEPrint, (void**) &pLeadPrnt); 
   if(FAILED(hr)) 
      return; 

   hr = ::CoCreateInstance(CLSID_EpnOemPrinterInfo, NULL, CLSCTX_ALL, IID_IEpnOemPrinterInfo, (void**) &pOemPrinterInfo); 
   if(FAILED(hr)) 
      return; 
   
   hr = ::CoCreateInstance(CLSID_EpnPrinterList, NULL, CLSCTX_ALL, IID_IEpnPrinterList, (void**) &pPrintersList); 
   if(FAILED(hr)) 
      return; 

   hr = ::CoCreateInstance(CLSID_EpnBatchPrinterInfo, NULL, CLSCTX_ALL, IID_IEpnBatchPrinterInfo, (void**) &pBatchPrinterInfo); 
   if(FAILED(hr)) 
      return; 

   hr = ::CoCreateInstance(CLSID_EpnMailMessageInfo, NULL, CLSCTX_ALL, IID_IEpnMailMessageInfo, (void**) &pMailMessageInfo); 
   if(FAILED(hr)) 
      return; 

   hr = ::CoCreateInstance(CLSID_EpnMultiSaveOptions, NULL, CLSCTX_ALL, IID_IEpnMultiSaveOptions, (void**) &pMultiSaveOptions); 
   if(FAILED(hr)) 
      return; 

   hr = ::CoCreateInstance(CLSID_EpnPrinterSpecifications, NULL, CLSCTX_ALL, IID_IEpnPrinterSpecifications, (void**) &pPrinterSpecifications); 
   if(FAILED(hr)) 
      return; 

   hr = ::CoCreateInstance(CLSID_EpnMailConfigurationSettings, NULL, CLSCTX_ALL, IID_IEpnMailConfigurationSettings, (void**) &pMailConfigurationSettings); 
   if(FAILED(hr)) 
      return; 

   if (pLeadPrnt->IsSupportLocked(SUPPORT_OEM)) 
      pLeadPrnt->UnlockSupport (SUPPORT_OEM, OEM_KEY); 
   
   //Prepare Printer Specifications
   
   //Custom Papers IDs starts from "DMPAPER_USER + 200"
   pPrinterSpecifications->PaperID = DMPAPER_USER + 200; 
   pPrinterSpecifications->PaperSizeName = "Custom Paper Name";
   pPrinterSpecifications->PaperHeight = 11; 
   
   pPrinterSpecifications->PaperWidth = 8; 
   pPrinterSpecifications->DimensionsInInches = true; 
   pPrinterSpecifications->PortraitOrient = true; 
   pPrinterSpecifications->MarginsPrinter = "Margins Printer Name";
   pPrinterSpecifications->PrintQuality = 300; 

   pPrinterSpecifications->YResolution = 300; 
   
   //Prepare Save Options
   
   pMultiSaveOptions->UseSave = true; 
   pMultiSaveOptions->SaveElementsCount = 1; 
   
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->FileName = "C:\\Untitled.cmp";
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->Format = FILE_CMP; 
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->DocumentType = FT_SAVE_TYPE_RASTER; 
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->RasterOptions->BitsPerPixel = 24; 
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->RasterOptions->QFactor = 100; 
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->RasterOptions->StampBits= 24; 
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->RasterOptions->StampWidth = 128; 
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->RasterOptions->StampHeight = 128; 
   pMultiSaveOptions->GetPrinterSaveOptions(0)->SaveOptions->RasterOptions>MultiPageFile = false; 
   
   IEpnNamingOptions *pNamingOptions = NULL; 
   pNamingOptions = pMultiSaveOptions->GetPrinterSaveOptions(0)->GetNamingOptions();
   pLeadPrnt->GetDefaultNamingOptions(&pNamingOptions); 

   //Prepare Mail Message
   pMailMessageInfo->UseMail = true; 
   pMailMessageInfo->To = "someone@somedomain.com";
   pMailMessageInfo->Cc = "another@anotherdomain.com";
   pMailMessageInfo->Bcc = "someonespecial@anotherdomain.com";
   pMailMessageInfo->Subject = "Attached Images";
   pMailMessageInfo->Body = "Hello, attached are the images."; 

   //Index of the save options index want to be used to save the e-mailed files. 
   //It is the index of the PrinterSaveOptions property in the EpnMultiSaveOptions
   //passed to the SetPrinterSaveOptions. 
   pMailMessageInfo->EmailSaveOptionsIndex = 0; 
   
   //Prepare Printers List
   //This will add the Default Printer to the Printers List
   pBatchPrinterInfo->PrinterName = "";//Printer.DeviceName; 
   pLeadPrnt->GetDefaultEnhancedOptions(&pBatchPrinterInfo->EnhancedOptions); 
   pBatchPrinterInfo->Flags = VALID_ENHANCED_OPTIONS; 
   pPrintersList->AddPrinter(pBatchPrinterInfo); 

   //Prepare Printer Info
   pOemPrinterInfo->OEMDriverName = "Test Driver Name";
   pOemPrinterInfo->OEMPrinterName = TEST_PRINTER_NAME; 
   pOemPrinterInfo->OEMMonitorName = "";
   pOemPrinterInfo->OEMPortName = "";
   pOemPrinterInfo->OEMProductName= "OEM ePrint";
   pOemPrinterInfo->OEMSerialNumber= "xxxxx-xxxxx-xxxxx";
   pOemPrinterInfo->OEMRegistryKey= "Test Printer Inc."; 
   pOemPrinterInfo->OEMRootDir= "C:\\Program Files\\OEM";
   pOemPrinterInfo->OEMHelpFile= "C:\\Program Files\\OEM\\OEM.hlp";
   pOemPrinterInfo->OEMPassword= "Test Password";
   pOemPrinterInfo->OEMUrl= "http://www.eprintdriver.com";

   nRet = pLeadPrnt->InstallOEMPrinter(pOemPrinterInfo, PRINTER_OEM_NORMAL); 
   
   if(nRet == 0) 
   {
      //Set OEM Printer Specifications
      pLeadPrnt->SetPrinterSpecifications(TEST_PRINTER_NAME, pPrinterSpecifications); 
      
      //Set OEM Printer Save Options
      pLeadPrnt->SetPrinterSaveOptions(TEST_PRINTER_NAME, pMultiSaveOptions); 
   
      //Set OEM Printer Renaming Options
      IEpnRenamingOptions * pRenamingOptions = NULL; 
      pLeadPrnt->GetDefaultRenamingOptions(&pRenamingOptions); 
      pLeadPrnt->SetPrinterConflictSolving(TEST_PRINTER_NAME, SAVE_APPEND_FAVOR_RENAME, pRenamingOptions); 
      
      //Set OEM Printer Mail Message
      pLeadPrnt->SetPrinterMailMessageInfo(TEST_PRINTER_NAME, pMailMessageInfo); 
   
      //Set OEM Printer Batch Printers List
      pLeadPrnt->SetPrinterBatchPrintersList(TEST_PRINTER_NAME, pPrintersList); 
   
      //Set OEM E-Mail Configurations
      pMailConfigurationSettings->IsMAPI = true; 
      pMailConfigurationSettings->UseDefaultMapiProfile = true; 
      pMailConfigurationSettings->Flags = 0; 
      pLeadPrnt->SetPrinterEmailConfiguration(TEST_PRINTER_NAME, pMailConfigurationSettings); 
   }

   if(pPrinterSpecifications) 
   {
      pPrinterSpecifications->Release();
      pPrinterSpecifications = NULL; 
   }

   if(pMultiSaveOptions) 
   {
      pMultiSaveOptions->Release();
      pMultiSaveOptions = NULL; 
   }

   if(pMailMessageInfo) 
   {
      pMailMessageInfo->Release();
      pMailMessageInfo = NULL; 
   }

   if(pBatchPrinterInfo) 
   {
      pBatchPrinterInfo->Release();
      pBatchPrinterInfo = NULL; 
   }

   if(pPrintersList) 
   {
      pPrintersList->Release();
      pPrintersList = NULL; 
   }

   if(pOemPrinterInfo) 
   {
      pOemPrinterInfo->Release();
      pOemPrinterInfo = NULL; 
   }

   if(pLeadPrnt) 
   {
      pLeadPrnt->Release();
      pLeadPrnt = NULL; 
   }
   
   if(pMailConfigurationSettings) 
   {
      pMailConfigurationSettings->Release();
      pMailConfigurationSettings = NULL; 
   }
}