Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass an Interface to a different process

I use WM_COPYDATA to enable communication between my two processes A and B. There is no problem to exchange data with basic data types.

Now I have a problem, in some case I want to pass an Interface (IDispatch) from my process A to my process B. Is it possible?

like image 584
stanleyxu2005 Avatar asked Apr 08 '12 05:04

stanleyxu2005


1 Answers

It is not possible to directly pass an interface pointer to another process. Like any other pointer, an interface is only valid in the process address space that instantiates it at runtime. COM has its own mechanism for marshaling interfaces and data across process boundaries, even across different apartments in the same process. In the case of interfaces, that involves proxies and stubs which run in each process/apartment and communicate with each other using various IPC mechanisms, such as pipes, RPC, or TCP/IP. Have a look at these articles for how using interfaces across processes/apartments is accomplished:

Inter-Object Communication

Understanding Custom Marshaling Part 1

To do what you are asking for, without resorting to implementing custom marshaling, you would have to make one of the processes act as an out-of-process COM server, and then the other process can use CoCreateInstance() or GetActiveObject() to obtain an interface pointer to the server's object that works within its local address space, and let COM handle the marshaling details for you.

like image 90
Remy Lebeau Avatar answered Oct 04 '22 03:10

Remy Lebeau