From: George on
Hello everyone,


1.

For message pump code for COM STA, my question is, we just need to copy and
past the following code to STA owner thread, no need to implement any
functions to handle msg (e.g. hidden window message handler)?

(I think no need and I think COM Runtime will plug-in a message handler for
the hidden window, to process the msg and call related function
automatically?)

[Code]
MSG msg;
while (GetMessage (&msg, 0, 0, 0))
DispatchMessage (&msg);
[/Code]

2.

If all the message pump code are common, why not COM automatically generates
the code for all STA? Because some STA has the requirement of not handling
in-coming calls from other apartment?


thanks in advance,
George
From: Igor Tandetnik on
"George" <George(a)discussions.microsoft.com> wrote in message
news:4002DA27-F9BB-484C-A3C3-4AE8C424BED4(a)microsoft.com
> For message pump code for COM STA, my question is, we just need to
> copy and past the following code to STA owner thread, no need to
> implement any functions to handle msg (e.g. hidden window message
> handler)?

Yes, this is sufficient.

> If all the message pump code are common, why not COM automatically
> generates the code for all STA?

Because you may need a more elaborate message pump. Often, you run your
application's UI on the same thread you are doing COM work on (e.g. you
are hosting an ActiveX control in your window). Depending on your UI
needs, you may want to use APIs like TranslateMessage or
IsDialogMessage.
--
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


From: George on
Thanks Igor,


Do you also think my below statements are correct?

--------------------
.... I think COM Runtime will plug-in a message handler for the hidden
window, to process the msg and call related function automatically? So, the
target called function will receive expected function parameter other than
msg.
--------------------


regards,
George
From: SvenC on
Hi George,

> Do you also think my below statements are correct?
>
> --------------------
> ... I think COM Runtime will plug-in a message handler for the hidden
> window, to process the msg and call related function automatically?
> So, the target called function will receive expected function
> parameter other than msg.
> --------------------

Yes, CoInitialize will do that. But actually you don't plug in a message
handler when you create a window but you have to specify a WNDPROC
for that window. That WNDPROC is called when messages are processed.

--
SvenC
From: George on
Thanks SvenC,


> Yes, CoInitialize will do that. But actually you don't plug in a message
> handler when you create a window but you have to specify a WNDPROC
> for that window. That WNDPROC is called when messages are processed.
>

I think you mean the WNDPROC is provided by COM and registered when we call
CoInitialize for an STA?


regards,
George