tags:

views:

113

answers:

2

Hi, We have an end-user client which has it's central logical components inside an singleton-COM object. (Not propper singleton, but it uses global variables internally, so it would fail.) So that there should be only one instance per exe-file. Convenient while making the client.

However, I should now make a "client-simulator" to test the server-side. I therefore which to make 20 instances of the client-component. If I could make each instance instanciate in its own exe-host, then the singleton-issue would be handled.

Is there possible to create a COM-instance in it's own, dedicated, host-process?

Regards Leif

+2  A: 

My COM days are long gone, but as far as I remember, there's no built-in way to do that.

It might be easier to rewrite your code so it supports multiple instances than to go the one-process-per-instance route with COM, but here's what you could do:

  • Use thread-local storage for your global variables and write another CoClass, where each instance owns its own thread through which accesses to the class with the global variables are marshaled. This would at least allow you to avoid the performance impact of DCOM.

  • Write your own out-of-process exe server (similar to windows' DllHost.exe) to host your COM instances. This requires IPC (Inter-Process Communication), so you either have to code something yourself that marshals calls to the external process or use DCOM (presuming your COM object implements IDispatch)

Cygon
Good tips. I'm going to hope for the "magic key" a little bit more before doing it the "propper" way.
leiflundgren
+1  A: 

This other question mentioned a description of how to use DLLHost as a surrogate process: http://support.microsoft.com/kb/198891

I've never tried this myself, and I don't know off-hand if you can specify flags for the factories (which control if surrogates can be reused for multiple objects), but maybe you can tweak that via DCOMCNFG or OLEVIEW.

Kim Gräsman
Wouldn't this solution have all the instances reside in one DLLHOST-process? Rather each instance having it's very own private process?
leiflundgren
That's what I meant by my blather about class factories. When factories are registered in an out-of-process server, you can specify if you want to respond more than once to CoCreateInstance -- if not, a new server will be launched. See http://msdn.microsoft.com/en-us/library/ms679697(VS.85).aspx. You want REGCLS_SINGLEUSE. Question is if you can specify to DLLHOST which REGCLS you want to use... I'm not sure.
Kim Gräsman
Ah, sounds very interresting.I solved it this time by a work-around.But the "next time" I should look more at this.Thanks!
leiflundgren