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

605 views
Skip to first unread message

JohnD

unread,
Feb 7, 2008, 9:13:30 AM2/7/08
to
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!_KiFastSystemCallRet@0()
user32.dll!_NtUserPeekMessage@20() + 0xc bytes
user32.dll!_PeekMessageW@20() + 0x167 bytes
> 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

unread,
Feb 7, 2008, 8:19:57 PM2/7/08
to
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

unread,
Feb 8, 2008, 6:52:30 AM2/8/08
to
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


"Norman Bullen" <no...@BlackKittenAssociates.com> wrote in message
news:13qnatj...@corp.supernews.com...

paulbonneau

unread,
Jul 9, 2010, 3:39:32 PM7/9/10
to
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!_KiFastSystemCallRet@0()
user32.dll!_NtUserPeekMessage@20() + 0xc bytes
user32.dll!_PeekMessageW@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 a
listed in my first mail, the app seems to be hung in the KiFastSystemCallRet
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!_KiFastSystemCallRet@0()
user32.dll!_NtUserPeekMessage@20() + 0xc bytes
user32.dll!_PeekMessageW@20() + 0x167 bytes

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

Norm

--
Norm

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

Paul Baker

unread,
Jul 27, 2010, 1:18:47 PM7/27/10
to
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.

> 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

<Paul Bonneau> wrote in message news:20107915392...@comcast.net...

devot...@gmail.com

unread,
Aug 10, 2016, 10:36:27 AM8/10/16
to
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
Reply all
Reply to author
Forward
0 new messages