Access COM object through a windows process handle.

Posted by Sivvy on Stack Overflow See other posts from Stack Overflow or by Sivvy
Published on 2010-04-30T18:02:32Z Indexed on 2010/04/30 18:07 UTC
Read the original article Hit count: 387

Filed under:
|
|

I'm currently automating an application at work using COM, and have an issue where anyone using my application has a problem if the original application is already open when my application runs. I know how to locate the process if it's open, but instead of having to worry about closing it, or working around it, etc., I want to try to use the existing application instead of opening a new one.

This is how I normally start the application in my automation program:

Designer.Application desApp = new Designer.Application();

Now I'm attempting to try and use the handle from an existing application:

Designer.Application desApp = (Designer.Application)((System.Diagnostics.Process.GetProcessesByName("Designer.exe")[0]).Handle)

(I know this doesn't work, since .Handle returns an IntPtr, but I'm using it as an example.)

Is there any way to accomplish this? How do I return a usable object if I know the handle/process?

© Stack Overflow or respective owner

Related posts about c#

Related posts about com