Re: CoInitialize[Ex] somehow returns S_OK in constructor of COM object being created
"Dmitry Shandyba" <shandyba@gmail.com> wrote in message
news:44b346b8-5100-41bb-8700-aba01ff2848a@e25g2000prg.googlegroups.com
The real idea is that, yes, as per James, I can see cross-thread calls
to take place where they are not actually expected to be seen (as all
object are marked with "both" now, at least during tests performed),
with subsequent failing QueryInterface.
"Both" just means that an object can be instantiated from either an STA
or an MTA. But once created in a particular apartment, it continues to
live in this apartment. A client can create a both-threaded object in
one apartment, then explicitly marshal its interface pointer to another
apartment (e.g. with CoMarshalInterThreadInterfaceInStream /
GoGetInterfaceAndReleaseStream). This would introduce a proxy, and
result in cross-apartment calls being made. This is normal.
See also CoCreateFreeThreadedMarshaler.
But it all turns to be different if I preceed all these operations
with CoInitializeEx, something I was referring to before and that is
very, very strange as far as I think.
And that means that the client sometimes calls your object from a thread
that didn't initialize COM at all. This is a blatant violation of COM
rules, of course. If this is the case, the client is broken and needs to
be fixed.
--
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