How to use one instance of a COM object in different processes?
-
Hi everyone, I am not able to find a way how to use the only one (common) instance of my COM object from several processes. Here I see the only solution of multiple instances and that way I lose some of the pointers. Can anybody guide me how to do that? Thanks, Jawid
-
Hi everyone, I am not able to find a way how to use the only one (common) instance of my COM object from several processes. Here I see the only solution of multiple instances and that way I lose some of the pointers. Can anybody guide me how to do that? Thanks, Jawid
-
Hi everyone, I am not able to find a way how to use the only one (common) instance of my COM object from several processes. Here I see the only solution of multiple instances and that way I lose some of the pointers. Can anybody guide me how to do that? Thanks, Jawid
If you com object was developed using ATL then there is a macro you can use to make it a singleton, meaning only one instance of it will be created and shared between all clients. Im sorry but i can't remeber what the macro is, its something like ATL_DECLARE_SINGLETON. Have a poke around in the MSDN although i found it in one of the wrox atl books.
-
Have you tried using RegisterActiveObject, to put your object in the ROT? Then you can use GetActiveObject. Scot Brennecke Software Developer VC++ MVP
I found that macro : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/vcoriATLMacrosAlphabeticalReference.asp The particular one is : DECLARE_CLASSFACTORY_SINGLETON Hope this helps.
-
Hi everyone, I am not able to find a way how to use the only one (common) instance of my COM object from several processes. Here I see the only solution of multiple instances and that way I lose some of the pointers. Can anybody guide me how to do that? Thanks, Jawid
Hi, I’m sorry but I did not fully understand your question? You want to use the some instance of a COM object in different processes or different threads in the same process? If you want to pass a pointer to a object to another thread in a running process you have to be aware of the COM Threading Model (Apartments) and Marshalling see http://www.codeguru.com/activex/COMApartments1.html and http://www.codeguru.com/activex/COMApartments2.html . . If you really want different processes to access the same COM object, then this last has to be implemented in a out-process (.exe) COM server having the class factory returning the same object every time a instance of that class is requested. Remember that using an out-process com server you’ll be linking whit a proxy/stub dll (Marshalling). http://www.codeguru.com/activex/MiniDcom.html I recommend you reading Essential COM (Don Box), ATL Internals (Brent Rector) and Learning DCOM (Thuan L. Thai)
-
Hi everyone, I am not able to find a way how to use the only one (common) instance of my COM object from several processes. Here I see the only solution of multiple instances and that way I lose some of the pointers. Can anybody guide me how to do that? Thanks, Jawid
-
Hi Guys, Thanks for great help. All of those advices seem very helpfull. I tried the solution with macro for singleton object and it works nice. Thanks,