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

Re: message pump code for COM STA by Igor

Igor
Thu Apr 10 21:57:02 CDT 2008

"George" <George@discussions.microsoft.com> wrote in message
news:4002DA27-F9BB-484C-A3C3-4AE8C424BED4@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



Re: message pump code for COM STA by George

George
Thu Apr 10 22:21:00 CDT 2008

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

Re: message pump code for COM STA by SvenC

SvenC
Fri Apr 11 01:39:18 CDT 2008

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

Re: message pump code for COM STA by George

George
Fri Apr 11 02:44:01 CDT 2008

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

Re: message pump code for COM STA by SvenC

SvenC
Fri Apr 11 03:10:53 CDT 2008

Hi George,

>> 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?

Lookup CreateWindow and RegisterClass to see how windows and
WNDPROCs work.

--
SvenC

Re: message pump code for COM STA by George

George
Fri Apr 11 04:38:01 CDT 2008

Sorry, SvenC!


My question is not how CreateWindow/RegisterClass/WNDPROC works, but who is
responsible to write WNDPROC and register it in the case of STA message pump
for the handler for the hidden window? The question is which party does this.
I think COM Runtime does this during CoInitialize(), right?


regards,
George

Re: message pump code for COM STA by SvenC

SvenC
Fri Apr 11 05:50:56 CDT 2008

Hi George,

> My question is not how CreateWindow/RegisterClass/WNDPROC works, but
> who is responsible to write WNDPROC and register it in the case of
> STA message pump for the handler for the hidden window? The question
> is which party does this. I think COM Runtime does this during
> CoInitialize(), right?

Yes.

Why do you ask the same questions over and over again. Igor answered this
question in "C++ COM STA model" on 24th of march. See below.

"George" <George@discussions.microsoft.com> wrote in message
news:25E267B5-0538-437B-9788-AFEDB2EC2BDB@microsoft.com
> In COM STA model, a hidden Window will be created with synchronized
> message pump operation.

Not quite. COM will create a hidden window. Your thread is responsible
for pumping messages to it (except in certain situations where COM
enters a modal message pump, e.g. when you make an out-of-apartment COM
call).

> 1. Who (which party) is responsible for generating code to create the
> hidden Window

COM creates a hidden window in CoInitialize. I'm not sure what you mean
by "generating code".

--
SvenC

Re: message pump code for COM STA by George

George
Sat Apr 12 02:51:01 CDT 2008

Thanks SvenC,


Sorry I missed some notification emails. Now I am using Yahoo mail box to
pump mail message so that my local disk is not full with message. :-)

> Not quite. COM will create a hidden window. Your thread is responsible
> for pumping messages to it (except in certain situations where COM
> enters a modal message pump, e.g. when you make an out-of-apartment COM
> call).

I understand what means make an out-of-apartment COM call, but I do not
understand why it is the same thing as "COM enters a modal message pump"?
Why? What are the differences modal message pump and normal message pump?


regards,
George

Re: message pump code for COM STA by SvenC

SvenC
Sat Apr 12 06:04:59 CDT 2008

Hi George,

> Sorry I missed some notification emails. Now I am using Yahoo mail
> box to pump mail message so that my local disk is not full with
> message. :-)

Hmm - you even answered to Igors answer and it turned out to get a
long thread like always.

>> Not quite. COM will create a hidden window. Your thread is
>> responsible for pumping messages to it (except in certain situations
>> where COM enters a modal message pump, e.g. when you make an
>> out-of-apartment COM call).
>
> I understand what means make an out-of-apartment COM call, but I do
> not understand why it is the same thing as "COM enters a modal
> message pump"? Why? What are the differences modal message pump
> and normal message pump?

It is like modal dialog and modeless dialog: when you display a modal
dialog that is a synchronous call which does not return before the modal
dialog is closed. To do that the modal dialog has its own message pump
which processes all messages, so that the window displays and user
events are handled.

So when you make a cross-apartment call that will look to you as a
synchronous call: your code does not continue before the COM method
call finished. Under the hoods the COM runtime will pump messages
until it gets the result message of the call. This message pump can be
called modal as it takes control until the result from the other apartment
has come in.

--
SvenC

Re: message pump code for COM STA by George

George
Sat Apr 12 06:48:00 CDT 2008

Thanks SvenC,


Your reply is clear.


regards,
George