Discussion:
Why would PeekMessage(&msg,0,0,0,PM_NOREMOVE) hang?
(too old to reply)
JohnD
2008-02-07 14:13:30 UTC
Permalink
Raw Message
Hello all,

I have a case where PeekMessage(&msg,0,0,0,PM_NOREMOVE) hangs.

My understanding of PeekMessage is that it returns "If no messages are
available, the return value is zero." So under what circumstances might it
hang?

The full code snippet is more like:

if (HIWORD(GetQueueStatus(QS_ALLINPUT)))
return PeekMessage(&msg,0,0,0,PM_NOREMOVE);

The relevant call stack is listed below.
ours.dll!WindowsMessageWaiting() Line 1054 + 0x12 bytes C
ours.dll!MessageLoop(int (void)* readfn=0x03e2ac70) Line 1161 + 0x18
bytes C

Thanks for your help.

/john
Norman Bullen
2008-02-08 01:19:57 UTC
Permalink
Raw Message
Post by JohnD
Hello all,
I have a case where PeekMessage(&msg,0,0,0,PM_NOREMOVE) hangs.
My understanding of PeekMessage is that it returns "If no messages are
available, the return value is zero." So under what circumstances might
it hang?
if (HIWORD(GetQueueStatus(QS_ALLINPUT)))
return PeekMessage(&msg,0,0,0,PM_NOREMOVE);
The relevant call stack is listed below.
ours.dll!WindowsMessageWaiting() Line 1054 + 0x12 bytes C
ours.dll!MessageLoop(int (void)* readfn=0x03e2ac70) Line 1161 + 0x18
bytes C
Thanks for your help.
/john
MSDN says "The PeekMessage function dispatches incoming sent messages..."

Perhaps a sent message is hanging in its window procedure.

Norm
--
Norm

To reply, change domain to an adult feline.
JohnD
2008-02-08 11:52:30 UTC
Permalink
Raw Message
Hi Norman,

But then I'd see my window proc on the stack. The top of the C-stack is as a
listed in my first mail, the app seems to be hung in the KiFastSystemCallRet
function.

/john
Post by Norman Bullen
Post by JohnD
Hello all,
I have a case where PeekMessage(&msg,0,0,0,PM_NOREMOVE) hangs.
My understanding of PeekMessage is that it returns "If no messages are
available, the return value is zero." So under what circumstances might
it hang?
if (HIWORD(GetQueueStatus(QS_ALLINPUT)))
return PeekMessage(&msg,0,0,0,PM_NOREMOVE);
The relevant call stack is listed below.
ours.dll!WindowsMessageWaiting() Line 1054 + 0x12 bytes C
ours.dll!MessageLoop(int (void)* readfn=0x03e2ac70) Line 1161 + 0x18
bytes C
Thanks for your help.
/john
MSDN says "The PeekMessage function dispatches incoming sent messages..."
Perhaps a sent message is hanging in its window procedure.
Norm
--
Norm
To reply, change domain to an adult feline.
Paul Bonneau
2010-07-09 19:39:32 UTC
Permalink
Raw Message
Hi John,

Did you ever find out the culrpit behind your hang? I have a similar problem:

Code:

MSG msg;
for (;;)
{
if (WAIT_FAILED != ::MsgWaitForMultipleObjectsEx(1, &hsem, INFINITE, QS_ALLINPUT, MWMO_INPUTAVAILABLE))
{
::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
.
.
.
}

Which will on the rare occasion hang with this call stack:

ntdll.dll!***@0()
user32.dll!***@20() + 0xc bytes
user32.dll!***@20() + 0x167 bytes

This was observed on a single-proc XPSP3 box.

- Paul.



JohnD wrote:

Hi Norman,But then I'd see my window proc on the stack.
08-Feb-08

Hi Norman

But then I'd see my window proc on the stack. The top of the C-stack is as
listed in my first mail, the app seems to be hung in the KiFastSystemCallRe
function

/john

Previous Posts In This Thread:

On Thursday, February 07, 2008 9:13 AM
JohnD wrote:

Why would PeekMessage(&msg,0,0,0,PM_NOREMOVE) hang?
Hello all

I have a case where PeekMessage(&msg,0,0,0,PM_NOREMOVE) hangs

My understanding of PeekMessage is that it returns "If no messages are
available, the return value is zero." So under what circumstances might it
hang

The full code snippet is more like

if (HIWORD(GetQueueStatus(QS_ALLINPUT))
return PeekMessage(&msg,0,0,0,PM_NOREMOVE)

The relevant call stack is listed below

ntdll.dll!***@0(
user32.dll!***@20() + 0xc byte
user32.dll!***@20() + 0x167 byte
ours.dll!MessageLoop(int (void)* readfn=0x03e2ac70) Line 1161 + 0x18
bytes

Thanks for your help

/john

On Thursday, February 07, 2008 8:19 PM
Norman Bullen wrote:

Re: Why would PeekMessage(&msg,0,0,0,PM_NOREMOVE) hang?
JohnD wrote
MSDN says "The PeekMessage function dispatches incoming sent messages...

Perhaps a sent message is hanging in its window procedure

Nor

--
Nor

To reply, change domain to an adult feline.

On Friday, February 08, 2008 6:52 AM
JohnD wrote:

Hi Norman,But then I'd see my window proc on the stack.
Hi Norman

But then I'd see my window proc on the stack. The top of the C-stack is as
listed in my first mail, the app seems to be hung in the KiFastSystemCallRe
function

/john


Submitted via EggHeadCafe - Software Developer Portal of Choice
ASP.NET Providerless Custom Forms Authentication, Roles and Profile with MongoDb
http://www.eggheadcafe.com/tutorials/aspnet/27f836b7-2c9e-4942-9712-1c7b901cadcc/aspnet-providerless-custom-forms-authentication-roles-and-profile-with-mongodb.aspx
Paul Baker
2010-07-27 17:18:47 UTC
Permalink
Raw Message
Are you certain that PeekMessage never returns? Or is it that
MsgWaitForMultipleObjectEx never returns (not necessarily on the first
iteration)?

This code needs improved error handling, you do not mention the result of
either function, I wonder why you use MsgWaitForMultipleObjectEx rather than
MsgWaitForMultipleObjects (may be no reason) and there are a lot of
undocumented details. However, I can answer your original question.
Post by JohnD
My understanding of PeekMessage is that it returns "If no messages are
available, the return value is zero." So under what circumstances might it
hang?
PeekMessage:
http://msdn.microsoft.com/en-us/library/ms644943(VS.85).aspx

The PeekMessage documentation says "During this call, the system delivers
pending, nonqueued messages, that is, messages sent to windows owned by the
calling thread using the SendMessage, SendMessageCallback,
SendMessageTimeout, or function.". Therefore, it may be handling nonqueued
messages. Calling PeekMessage is indicating that you are at a "safe"
interval to handle messages, so it opens the floodgate. The messages would
be coming from a different thread. You can investigate this simply by
stepping carefully in the debugger.

Paul
Post by JohnD
Hi John,
MSG msg;
for (;;)
{
if (WAIT_FAILED != ::MsgWaitForMultipleObjectsEx(1, &hsem, INFINITE,
QS_ALLINPUT, MWMO_INPUTAVAILABLE))
{
::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
.
.
.
}
This was observed on a single-proc XPSP3 box.
- Paul.
Hi Norman,But then I'd see my window proc on the stack.
08-Feb-08
Hi Norman,
But then I'd see my window proc on the stack. The top of the C-stack is as a
listed in my first mail, the app seems to be hung in the
KiFastSystemCallRet
function.
/john
On Thursday, February 07, 2008 9:13 AM
Why would PeekMessage(&msg,0,0,0,PM_NOREMOVE) hang?
Hello all,
I have a case where PeekMessage(&msg,0,0,0,PM_NOREMOVE) hangs.
My understanding of PeekMessage is that it returns "If no messages are
available, the return value is zero." So under what circumstances might it
hang?
if (HIWORD(GetQueueStatus(QS_ALLINPUT)))
return PeekMessage(&msg,0,0,0,PM_NOREMOVE);
The relevant call stack is listed below.
ours.dll!MessageLoop(int (void)* readfn=0x03e2ac70) Line 1161 + 0x18
bytes C
Thanks for your help.
/john
On Thursday, February 07, 2008 8:19 PM
Re: Why would PeekMessage(&msg,0,0,0,PM_NOREMOVE) hang?
MSDN says "The PeekMessage function dispatches incoming sent messages..."
Perhaps a sent message is hanging in its window procedure.
Norm
--
Norm
To reply, change domain to an adult feline.
On Friday, February 08, 2008 6:52 AM
Hi Norman,But then I'd see my window proc on the stack.
Hi Norman,
But then I'd see my window proc on the stack. The top of the C-stack is as a
listed in my first mail, the app seems to be hung in the
KiFastSystemCallRet
function.
/john
Submitted via EggHeadCafe - Software Developer Portal of Choice
ASP.NET Providerless Custom Forms Authentication, Roles and Profile with MongoDb
http://www.eggheadcafe.com/tutorials/aspnet/27f836b7-2c9e-4942-9712-1c7b901cadcc/aspnet-providerless-custom-forms-authentication-roles-and-profile-with-mongodb.aspx
d***@gmail.com
2016-08-10 14:36:20 UTC
Permalink
Raw Message
Hi all. Have you found a solution for this problem? I'm having a similar problem.

My program is stuck inside PeekMessage (with HWND = NULL).
The stack is:

USER32!PeekMessage
USER32!GetKeyState
USER32!PeekMessageA (my call)

Thank you,
-- Fred

Loading...