Re: COM Apartments - Message Loops
Actually, that's an undocumented internal implementation detail
of COM. Any thread which has not explicitly entered an
apartment is considered as belonging to the process' MTA.
It's unclear how this behaves if you haven't created the MTA
explicitly and may even differen on different versions of Windows.
At least one version of Windows 2000 (Gold, or SP1, or SP2,
not sure) had this practice abolished. This broke some third
party applications I suppose, because Microsoft reinstated the
In short, I'd strongly discourage you to rely on undocumented
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://www.mvps.org/vcfaq
"Ron Ayoub" <email@example.com> wrote in message
I think your comments are very helpful. The only other thing is, why is
an exception thrown when you don't call CoInitialize* in a thread and
attempt to create a COM object but when you spawn a new thread from one
that called CoInitialze* and you don't call CoInitialize* you are
still able to create a COM object without getting an exception. This
seems to indicate that the context of the initialze CoInitialize* call
propagates to the spawn thread. It is natural to expect that when this
is the behavior. That is why I was lead to that initial belief.
Igor Tandetnik wrote:
Ron Ayoub <firstname.lastname@example.org> wrote:
Ok. I appreciate your help. I'm getting close to understanding this.
What I think I'm trying to say is that you don't need to have a
message pump in your thread but you need to be aware that there is a
hidden window associated with the STA thread that needs to be pumped
on occassion with a call to a function like MsgWaitForSingleObject().
"Call MsgWaitForSingleObject periodically" is just another way to say
"run a message pump".
The literature confuses me a bit. I get confused on whether I need to
PeekMessages etc... or just Pump messages in the hidden window.
It does not matter. You need to retrieve messages from the queue and
dispatch them to appropriate window. The exact technique of doing that
is up to you.
With best wishes,
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