tags:

views:

150

answers:

1

Who is responsible for calling CoInitialize and CoUninitialize if

1- I host a COM dll within a surrogate process (either by using dcomcnfg utility or COM+ wizard)?

2- I build a ISAPI DLL that contains COM objects?

A: 

No idea on case 2, but in case 1 the surrogate process certainly calls CoInitialize()/CoUninitialize(). Here's how I know this.

We have a COM object that we host in COM+ and that itself uses MS XML 4. When you need to create an XML document object in MS XML 4 you call CoCreateInstance(). We never call CoInitialize() in our COM object, yet document creation is always successful - certainly the surrogate calls CoInitialize(). If we do the same in a stand-alone app document creation fails unless we ourself call CoInitialize().

So the bottom line is: COM+ surrogate (and I'm sure that applies to DCOM surrogate as well) calls CoInitialize() itself.

Btw you can use this to investigate the case 2 - call CoCreateInstance() inside the ISAPI dll - if it is successful CoInitialize() has already been called.

sharptooth
Thanks for reply. Do you have any idea whether COM+ surrogate joins a STA or MTA?
arnold
@arnold: Looks like it depends on the COM object treading model: http://msdn.microsoft.com/en-us/library/ms681753(VS.85).aspx
sharptooth