Resending: VSS Out-Of-Process COM server, threading models, and marshalling


2008-07-28 09:15:05 PM
delphi161
I'm sending this again; for some reason it seems it hasn't appeared properly
(I think the double-dot over the "i" in "naive" fouled up the message),
though it shows up properly on my Outlook Express.
Hello,
Sorry if my questions seem naive, but I am still trying to find my way on
the vast universe of COM.
Here is the context:
I'm connecting to the VSS (Volume Shadow Service) COM server (on a Windows
XP system) via its type library that I imported into Delphi. The server is
"vssvc.exe" so I have presumed it runs as an "out-of-process" server. I
launch threads within my client application; these threads make calls to it,
after calling CoInitializeEx, and afterwards they call CoUninitialize once
they've finished with the VSS object ("VSSCoordinator").
The threads do not directly access the VSS server; in fact my client exe
first connects to an in-process COM dll and accesses an automation object
(MyAutoObject) which follows the apartment model; i.e. it uses the following
statement in its "initialization" clause:
TAutoObjectFactory.Create(ComServer, TMyAutoObject,
CLASS_MyAutoObject,ciInternal, tmApartment);
after which, MyAutoObject connects to the VSS server.
So far, to make sure of safety, I have ensured via a system-wide (named)
mutex that only one thread at a time can access the server. This was learnt
the hard way of course: I found that if I launched two threads on the VSS
server, the second thread's commands failed.
I understand that "out-of-process" servers do not specify a threading model
(while in-process servers must do so), and that all the client-server
communication is marshalled (whether the threading models used by client and
server are the same or not) and RPC is used.
With what do I call CoInitializeEx for the threads in my client exe:
COINIT_MULTITHREADED or COINIT_APARTMENTTHREADED? Does it make a difference,
or will everything be marshalled the same way anyway? What would be safer?
I've been reading horror stories about how launching with an STA caused the
whole system to hang after a lot of calls :(
A more efficient method of handling access to the object could be by pooling
in some way instead of forcing a mutex. Would this be possible with the VSS
object? How do I find out what the out-of-process server is capable of? (I
would expect such information to be in the registry...)
Note that I don't know how to tell whether the VSS server runs by itself or
as a dll surrogate, or what registry entries are concerned by it.
I hope someone can shed some light on my confusion. Thanks in advance.
Z