I am trying to open CorelDRAW from within my program using C#. So far I have been able to do so by referencing the appropriate com library and calling
CorelDRAW.Application draw = new CorelDRAW.Application();
draw.Visible = true;
However, I would like my program to work with any version of CorelDRAW that supports interop. I am attempting to use reflection to load the interop library at runtime, where the specific dll can be chosen for the correct version. From looking around I have tried the following.
string path = "Interop.CorelDRAW.dll";
Assembly u = Assembly.LoadFile(path);
Type testType = u.GetType("CorelDRAW.Application");
if (testType != null)
{
object draw = u.CreateInstance("CorelDRAW.Application");
FieldInfo fi = testType.GetField("Visible");
fi.SetValue(draw, true);
}
The program fails at u.CreateInstance...
fails because CorelDRAW.Application
is an interface, not a class. I have also tried replacing CorelDRAW.Application
with CorelDRAW.ApplicationClass
as that is available when I browse through Interop.CorelDRAW as a resource, but then u.getType...
fails.
How can I get this to work? Thank you!