0

My application has two executable (*.exe) files. The main program will start the secondary executable as a child process. The child process quickly calls CoCreateInstance(..., CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, ...) using the class id of the COM server hosted by the main program.

The problem is that if I start multiple instances of the main program, the child process might not always choose the parent process as its COM server. From what I can tell, the child process always chooses the first started instance of the main program.

Is there any way you can tell COM which process id to use as your local COM server?

Troy
  • 1,237
  • 2
  • 13
  • 27
  • [CreateProcess](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425.aspx) allows you to pass a command line to your child process. If you need to pass along identifiers, this is how to do it. Identifying COM objects can be done using [monikers](https://msdn.microsoft.com/en-us/library/windows/desktop/ms691261.aspx). – IInspectable Aug 30 '16 at 17:10
  • You cannot directly control which server instance COM will pick. If it finds one that promises REGCLS_MULTIPLEUSE then it is happy. Picking a *specific* process requires a hack that requires co-operation from the server, [described here](http://stackoverflow.com/a/2068135/17034).. – Hans Passant Aug 30 '16 at 17:23
  • 2
    Specifically, consider `IRunningObjectTable`. The server could make up a unique name and register itself under it (item monikers are handy for that, they are basically just an arbitrary string - see `CreateItemMoniker`). The child would then pick the correct server from the table by that name. Communicating the name from parent to child is left as an exercise for the reader. – Igor Tandetnik Aug 31 '16 at 04:49
  • Thanks to everyone for your comments. Igor, you had the solution. I translated the C++ from here (http://stackoverflow.com/questions/5156553/how-to-communicate-between-two-com-objects-using-running-object-table-rot) into Delphi and now I have total control over picking which instance of my COM server to connect to. Thanks! – Troy Aug 31 '16 at 19:38

0 Answers0