Re: C++ COM STA model
"George" <George@discussions.microsoft.com> wrote in message
news:AC4BB153-9FE7-40CE-9F83-7455BD527C84@microsoft.com
When do we need to explicitly program message loop in STA thread?
Almost always. You can get away without doing it if
a) the thread is very short-lived - it's created, makes a few COM calls,
and is destroyed, or
b) the thread spends most of its time waiting for outgoing
cross-apartment COM calls to return; such calls spin their own message
pumps, or
c) the thread displays a modal dialog box, or uses some other Windows
API that internally runs a message pump.
Like this code segment in the article. I have this question because I
noticed all samples in the article, including the ones for
cross-apartment do not explicitly get message, translate message and
dispatch message.
I guess the sample falls under one of the categories above, or else it
doesn't mind potentially freezing other applications while it's running.
Which I guess is not so bad for a sample, but not something you would
want your real application to do.
For marshelling between apartments, I think all stub/proxy code are
generated automatically by COM Runtime, right?
If your interface is not automation compatible, you have to build and
register proxy/stub DLL for it. If it is automation compatible, you may
still choose to build proxy/stub DLL, or you can build and register a
type library for it. COM provides so-called universal marshaller which
can marshal any automation-compatible interface based on its description
in the TLB.
--
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