GetActiveObject () vs GetObject () - MK_E_UNAVAILABLE error

All:

I'm having trouble translating some VBA code into C #.

We have a third-party application that acts as a local COM server.

In VBA code, we use GetObject () to get a reference to an existing object

eg.

Set appHandle = GetObject("", ProgId) 

it works great.

I added a link to a third-party application in our C # code and used Marshal.GetActiveObject () to try to get a link to the executable instance.

eg.

 var appModel = (IAppCoModel)Marshal.GetActiveObject(ProgId); 

but I keep getting MK_E_UNAVAILABLE .

Creating a new object works fine in C # code

eg.

 var appModel = new AppCoModel() 

this launches a third-party application and allows me to communicate with it. It only captures a reference to an executable instance that fails.

What i tried

Different security contexts
VS works in administrator mode, a third-party application does not. I tried to launch our C # application from the command line (non-admin). Still not working.

Check the contents of the ROT
(suggested by Marshal.GetActiveObject () throws MK_E_UNAVAILABLE exception in C # )
A third-party application does not appear in it. I do not know enough COM to be sure that this is necessary.

Checked all registry entries
Look good (as far as I can see) and they are good enough to create and instantiate a third-party application and for VBA to find it. Anything specific I should check here?

Any suggestions that people can make will be appreciated.

+3
source share
1 answer

All:

I'm not too sure that etiquette is for closing one question, but since I found the answer, I would like to somehow mark it as "not needing an answer."

The reason that GetActiveObject () returns MK_E_UNAVAILABLE is because the third-party application is not registered as an automation server. Unable to get link to executable instance.

This did not appear in VBA code because:

  • GetObject("",ProgID) creates a new instance each time ( http://msdn.microsoft.com/en-us/library/gg251785.aspx )

  • The public COM function in a third-party application launches the application if it is not running. Thus, in VBA, we create several objects, all pointing to the same application, not the application.

+6
source

All Articles