Re: How does PeekMessage really work?
- From: Denis Adamchuk <DenisAdamchuk@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 10 Sep 2008 02:26:15 -0700
Thanks for your links!
It's a good idea to analyze messages in WndProc or have a hook, say
WH_CALLWNDPROC for this purpose. But unfortunately it's too late to analyze a
message when it's already retrieved from the send-message queue because if I
don't want to handle it NOW - I cannot just return it to the queue, its
impossible.
"Malachy Moses" wrote:
On Sep 9, 9:39 am, Denis Adamchuk.
<DenisAdamc...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Malachy, thanks for your explanation.
I've carefully read the article by Raymond.
In the OldNewThing discussion I found a similar question about inter-thread
sent messages which are kept in a "separate place". This one is very
important for me now but it is still unanswered:
"Can I retrieve sent messages as if they were posted messages, and then
dispatch them? I would like to be able to filter out, for example, Shatter
attacks. "
In other words I would like to disable sent messages to be processed
(dispatched) within PeekMessage or allow it only for group of messages
(filter by ID).
< snip >
I don't have an answer for you, but I have some more information.
First, there might be a real name for the "separate place" mentioned
in Raymond Chen's blog. The name might be "send-message queue", and
the thread that sent the message might have a correspondingly-named
"reply-message queue". Both of these queues are distinctly different
from the so-called "message queue" that is serviced by GetMessage and
PeekMessage. Here are two links that talk about these topics, and
about the algorithm that the Windows system uses to service these
three queues.
"Sending Messages to a Window" at http://www.jamajm.com/e-books/cpprichter/HTML/ch26d.htm
"Waking a Thread" at
http://ymei.freeshell.org/gopher/Book/Programming%20Applications%20for%20MS%20Windows%204thed/ch26e.htm
Second, with respect to protection against shatter attacks, I think
the right place to do this is inside the WinProc itself. The WinProc
will get all messages, regardless of how they are sent/posted. Inside
the WinProc, you sill need to determine the origin of the message
(thread ID, maybe). Windows must somehow know of the origin, since
Windows needs to know where to send the LRESULT of your WinProc. I
don't know how to get the originating thread ID, however. It would be
nice if the API had a GetOriginOfMSg function, or if the MSG structure
included this information, but it doesn't. You probably will need to
look to undocumented Windows internals. Probably, the internal
structure for MSG must have some sort of identifier on where to send
the LRESULT, so that it ends up in the correct thread's reply-message
queue (per new terminology above).
Third, when I am trying to figure out how Windows works internally, I
often look at the source code for the WINE windows emulator. This
often provides good hints to me on what Windows is probably doing. In
your case, the files you might want to start with are windows/queue.c
and windows/message.c . See the explanation of the WINE messaging sub-
system, at the bottom of this link:
"Chapter 10. Windowing system" at http://www.winehq.org/site/docs/winedev-guide/c3764
Good luck. If you find an answer, please let us know.
- References:
- How does PeekMessage really work?
- From: Denis Adamchuk
- Re: How does PeekMessage really work?
- From: AliR \(VC++ MVP\)
- Re: How does PeekMessage really work?
- From: Malachy Moses
- Re: How does PeekMessage really work?
- From: AliR \(VC++ MVP\)
- Re: How does PeekMessage really work?
- From: Denis Adamchuk
- Re: How does PeekMessage really work?
- From: Malachy Moses
- Re: How does PeekMessage really work?
- From: Denis Adamchuk
- Re: How does PeekMessage really work?
- From: Malachy Moses
- How does PeekMessage really work?
- Prev by Date: Re: NM_CLICK on a tab control
- Next by Date: Where else can a programmer look for answers.
- Previous by thread: Re: How does PeekMessage really work?
- Next by thread: Re: How does PeekMessage really work?
- Index(es):
Relevant Pages
|