I need to connect to PDFCreator COM interface
from C# application. For this purpose, I use VS generated Interop wrappers. But some clients have different version of PDFCreator (I have 1.2.1, some have 1.4.3) and if I use Interop generated for 1.2.1 I get exception when using the wrapper. Is there any way around this? So my app can support multiple versions of PDFCreator?
Also, I am not sure wheather PDFCreator interface actually changed. Isn´t there some lock on exact version of COM object, I could simple turn off while generating Interop libraries? Thank you.
So, based on yms answer, I got in the right direction :)
.NET 4.0 supports late binding COM objects similiarly to VB, using System.Type
and the magic dynamic
keyword.
Simple example how to run PDFCreator using dynamic binding:
System.Type pdfCreatorType = System.Type.GetTypeFromProgID("PDFCreator.clsPDFCreator");
dynamic comPdfCreator = System.Activator.CreateInstance(pdfCreatorType);
comPdfCreator.cStart("", true);
This works like a charm, and you don´t need to recompile your Interop Assemblies for each new PDFCreator version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With