Re: CoInitialize/CoUninitialize
"Alf P. Steinbach" <alfps@start.no> wrote in message
news:BfmdnWLhn6dySfXVnZ2dnUVZ_ofinZ2d@posted.comnet
CoInitialize/CoUninitialize are per thread. Calling CoUninitialize in
one thread cannot affect other threads.
You'd think so, wouldn't you? :-)
But reality is a bit different.
In particular, there's much messaging between threads, and just to
make the point, the above is an actual case, not some hypothetical
silly-example.
You seem to be hinting at some dark secret only you know about. Do you
have any evidence to back up the claim? Perhaps a working sample where a
code similar to what you show causes problems?
I totally agree, it should. Ideally. Reality is that it doesn't. Or
didn't. Perhaps Microsoft has now fixed all their libraries (I doubt
it, however).
Again, can you show an example that would demonstrate the bug you
allege?
If you are willing to do the complete CoInitialize / CoUninitialize
dance just for checking, why not do it for real as in the first
example, and actually use the freshly initialized apartment
Because that doesn't work in general, but might work in particular
cases (it's like C++ Undefined Behavior), thus leading someone --
e.g. you! :-) -- to use it, and sometime in the future get some
very difficult-to-find bug.
The behavior of this code looks well defined and documented to me.
Again, what specifically do you believe is a problem with it?
I think the overhead is there only in the unreliable case where
CoInitialize actually initializes.
So you think calling CoInitialize and then immediately CoUninitialize
(when COM was not initialized before on this thread) is well defined,
but calling CoInitialize, then doing some COM work, and then calling
CoUninitialize is somehow different. What exactly do you believe is the
difference between these two cases?
Under your theory, when is it ever safe to call CoInitialize and
CoUninitialize? You say that calling CoInitialize for the first time in
a thread is "unreliable" - wouldn't that mean there's no reliable way to
use COM at all?
--
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