.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

Newbie COM interop question

I've got a .NET application where I want to launch a Delphi 3 EXE and control it remotely. The Delphi app has a COM interface, which I'm able to see if I import the Delphi EXE as a reference.

What I'd like to know is... where do I get started?

Here's how I've started things:

    Process p = System.Diagnostics.Process.Start("delphiapp.exe", "-parameters");
    Type myType = p.GetType();
    Type myType2 = myType.GetInterface("IMyInterface", true);
It appears myType pulls back a generic {Name = "Process" FullName = "System.Diagnostics.Process"} object, while myType2 is null.

Obviously this is wrong... and I'm not sure I've even approached getting a COM interface from the application correctly. Can anyone point me in the right direction?

Thursday, January 25, 2007
You can get the Type from the ProgId or CLSID using the methods Type.GetTypeFromProgID or Type.GetTypeFromCLSID.

Then call System.Activator.CreateInstance or System.Activator.GetObject to create an instance or connect to a running instance.
Thursday, January 25, 2007
COM interfaces in an application are typically out-of-proc COM objects.  That means if you create one it will launch the EXE for you so you do not have to do it yourself.

You can also add the COM interface to your app in the references section of the project and then create an instance pretty quickly.

I just had to make a sample on how to do this for someone at work so its all fresh in my mind.  Email if you have questions.
SteveM Send private email
Thursday, January 25, 2007
I figured it out -- kind of. This code does indeed launch the executable, which is good:

            ConsoleApplicationClass c = new ConApp.ConsoleApplicationClass();
            IConsoleApplication2 ic = c; // Get the interface I want
            Console.WriteLine(ic.Caption); // Example of getting something from the query.
One last question: Is there a way to pass a startup parameter to the executable when it starts up by creating a COM object?

Friday, January 26, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz