Re: CoInitialize[Ex] somehow returns S_OK in constructor of COM object being created
<JamieRThomson@lycos.co.uk> wrote in message
news:3fa5779a-9a7f-4223-831d-738ae89e6b1b@d27g2000prf.googlegroups.com
The answer is to change your threading model in the RGS file from
"Apartment" to "Both". Although an instance of your COM object does
not get called from multiple threads, there are multiple instances on
multiple threads and COM seems to get upset by this.
There's nothing wrong with multiple instances of an apartment-threaded
object being created on multiple threads, as long as each such thread
enteres STA. In fact, if the client never initializes MTA, both-threaded
object behaves exactly the same as apartment-threaded object. It is not
clear how changing from Apartment to Both is supposed to help things.
I cannot fully explain the COM black-magic but with "Apartment" set,
CoCreateInstance inserts a proxy to marshal calls from one thread to
another.
Only if the client calls CoCreateInstance from MTA thread. The OP states
this is not the case.
Setting "Both" should (and has for us on our other plugins) exhibit
the correct behaviour. You should probably use the multi-thread
variant of the ATL base classes (CComMultiThreadModel) but it's not
stricly required as your object is created, called and destroyed on
the same thread.
Not true. Both-threaded object can be accessed from multiple threads if
its client uses MTA.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925