Connect to Running Program via COM - Marshal.GetIUnknownForObject

47 views Asked by At

I am using a software package that offers an "extension" package, largely undocumented, that allows for creation of extensions that allow automation within the program. It's a COM interface between the addin/extension and the running software.

I have a need to connect and run the automation from outside the software, while the software is running.

The limited sample code shows a method that must be crearted that is called by the software when the addin is executed from the software:

 AppComExtensionWrapper m_wrapper;
 const int S_FALSE = 1;

 public int AppConnect(object unknown)
 {
     try
     {
         IntPtr p = Marshal.GetIUnknownForObject(unknown);
         return m_wrapper.AppComConnect(p);
     }
     catch
     {
         return S_FALSE;
     }
 }

When the extension is called from within the app, it calls the AppConnect method and passes the unknown object.

When running externally, how do I get the unknown object and connect to my app? Or is there another method to connect to the app?

I have tried looking through System.Diagnostics to get the running process but not sure how to get that to connect. I am somewhat stuck.

0

There are 0 answers