开发者

Exposing the same Auto of Process COM server from multiple copies of the same executable

开发者 https://www.devze.com 2023-03-13 18:25 出处:网络
I have a media application (written in Delphi 2010 but I am not sure that\'s entirely relevant) and it only allows one instance (via mutex).

I have a media application (written in Delphi 2010 but I am not sure that's entirely relevant) and it only allows one instance (via mutex).

One of my customers would like to run 2 instances of the app by duplicating its install and all of its application data as this will allow him to run the output to two different sound cards, giving him two audio zones.

Now I can allow the second instance via command line switch, thus creating a differently named mutex and even allowing him to send controls to either instance of the appliction via command line switches or windows message passing.

My application also exposes a COM interface for automation purposes, obviously this provides a much richer interface than command line and makes it much easier to get information out of the application.

So my problem is that, as far as I am aware, I can only expose the COM interface to one executable. Now I know that makes sense, but I am wondering if anyone can think of a workaround to this.

I had a quick try at duplicating the registry keys for my HKLM\Software\Classes\AppID thus making AppIDv2 and got as far as it lanching the other copy of my a开发者_如何学Cpp, but I guess it all came unstuck when it hit the more specific GUIDS for the TypeLib etc. Mind you, I know I overstepped the bounds of my knowledge!

My thought is that if I can create a different AppID string and ultimately target the exe sitting in different locations then we'd at least be able to do some automation via scripting COM Automation but I suspect that the requirement for GUIDs is ultimately going to let me down.

Another option may be to move my COM to inprocess and then have multiple compiled versions of my application that expose an instance of the main interface via new AppIDs, but that gets messy when you want the DLL to know all about the running instance of your application.

Any ideas welcome. Thanks in advance.


It sounds like you want to register yourself in the Running Objects Table (ROT).

i'm likening your problem to that of multiple copies of Excel running. COM has a mechanism to allow someone to find my the running instances of Excel and connect to one of them.

Out of process COM objects are expected to register themselves with the ROT. Callers can then use GetActiveObject to find your instance:

To automate an Office application that is already running, you can use the GetActiveObject() API function to obtain the IDispatch pointer for the running instance. Once you have this IDispatch pointer for the running instance, you can use the methods and the properties of the running instance.

You might not like it, but i believe the solution is that there is one application interface, and that "first" application acts as the gateway to other "instances" of your application (i.e. your automation server).

i'm not an expert in out-of-process COM automation, but i think i've read enough to believe that's the (unfortunate) answer.

See also

  • Registering the Active Object with API Functions
  • How To Attach to a Running Instance of an Office Application


You do indeed need the Running Object Table (IRunningObjectTable). Ian's answer is largely correct.

http://msdn.microsoft.com/en-us/library/ms695276(v=VS.85).aspx

However, it is possible to have two distinguishable instances in the ROT, allowing both copies of your app to be accessed because their monikers are distinguished.

Martyn

0

精彩评论

暂无评论...
验证码 换一张
取 消