| easyPDFオブジェクトの使用 |
全てのBCLのCOMオブジェクトは様々なプログラム環境からアクセスすることが可能です。このセクションではCOMオブジェクトとそれらへのアクセス方法の基本を紹介します。 既にCOMオブジェクトの使用に関してご存知の場合、サンプルコードの章へスキップして実際の作業を開始してください。
この例はVisual C#またはVisual Basic.NETからCOMオブジェクトへのアクセス方法を紹介しています。

| using
BCL.easyPDF.Interop.EasyPDFPrinter; // ... Printer oPrinter = null; PrintJob oPrintJob = null; try { Type type = Type.GetTypeFromProgID("easyPDF.Printer.5"); oPrinter = (Printer)Activator.CreateInstance(type); oPrintJob = oPrinter.PrintJob; oPrintJob.PrintOut(inFileName, outFileName); } catch(System.Runtime.InteropServices.COMException err) { // ... } |
| Imports
BCL.easyPDF.Interop.EasyPDFPrinter ' ... Dim oPrinter As Printer = Nothing Dim oPrintJob As PrintJob = Nothing Try oPrinter = CreateObject("easyPDF.Printer.5") oPrintJob = oPrinter.PrintJob oPrintJob.PrintOut(inFileName, outFileName) Catch ex As System.Runtime.InteropServices.COMException ' ... End Try |
この例はVisual BasicからCOMオブジェクトへのアクセス方法を紹介しています。

| Sub
Convert(inFileName As String, outFileName As String) Dim oPrinter As EasyPDFPrinter.Printer Dim oPrintJob as EasyPDFPrinter.PrintJob On Error GoTo Convert_Error Set oPrinter = CreateObject("easyPDF.Printer.5") Set oPrinjob = oPrinter.PrintJob Call oPrintJob.PrintOut(inFileName, outFileName) Exit Sub Convert_Error: ' ... End Sub |
この例はVisual C++からCOMオブジェクトへのアクセス方法を紹介しています。
| #import "C:\Program Files\Common Files\BCL Technologies\easyPDF 5\bepprint.dll" |
| HRESULT
hr = CoInitialize(NULL); if(FAILED(hr)) { // failed. // ... } |
| EasyPDFPrinter::IPrinterPtr pPrinter =
NULL; EasyPDFPrinter::IPrintJobPtr pPrintJob = NULL; try { pPrinter.CreateInstance(_T("easyPDF.Printer.5")); pPrintJob = pPrinter->GetPrintJob(); pPrintJob->PrintOut(lpInFileName, lpOutFileName); } catch(_com_error &e) { // ... } |
| //
IMPORTANT: // Make sure to free all COM objects before calling // CoUninitialize(), or you'll get an exception. pPrinter = NULL; pPrintJob = NULL; CoUninitialize(); |
この例はWindowsスクリプティングホストからCOMオブジェクトへのアクセス方法を紹介しています。
| <?xml version="1.0"
encoding="UTF-8" standalone="yes" ?> <package> <job id="demo"> <?job error="true" debug="true" ?> <object id="PrinterSDK" progid="easyPDF.Printer.5" reference="true" /> <script language="VBScript"> <![CDATA[ Set oPrinter = CreateObject("easyPDF.Printer.5") Set oPrinjob = oPrinter.PrintJob Call oPrintJob.PrintOut(inFileName, outFileName) ]]> </script> </job> </package> |