2
votes

Greetings all,

in my application i use the following code:

bool HandleMessages()
{
MSG msg;

if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
    if (msg.message == WM_QUIT)
        return FALSE;

    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

return true;
}

This is the standard code for message handling in windows i thought, but now when i try to run the program, i always get an Exception at the PeekMessage() call.

Exception message is

Unhandled exception at 0x57a10eed (msvcr100d.dll) in testing.exe: 0xC0000005: access violation while reading at Position 0x6666665c.

Im completely lost here, cant see why it would throw an exception. Anyone got a hint?

Call Stack:

msvcr100d.dll!__local_unwind2() + 0x48 Bytes Asm

msvcr100d.dll!_except_handler3() + 0xed Bytes Asm

Testing.exe!_except_handler4(_EXCEPTION_RECORD * ExceptionRecord, _EXCEPTION_REGISTRATION_RECORD * EstablisherFrame, _CONTEXT * ContextRecord, void * DispatcherContext) + 0x24 Bytes C

Testing.exe!_except_handler4(_EXCEPTION_RECORD * ExceptionRecord, _EXCEPTION_REGISTRATION_RECORD * EstablisherFrame, _CONTEXT * ContextRecord, void * DispatcherContext) + 0x24 Bytes C

Disassembly:

continue:

57CE0EEA lea esi,[esi+esi*2]
57CE0EED mov ecx,dword ptr [ebx+esi*4]
57CE0EF0 mov dword ptr [esp+0Ch],ecx
57CE0EF4 mov dword ptr [eax+0Ch],ecx
57CE0EF7 cmp dword ptr [ebx+esi*4+4],0
57CE0EFC jne _lu_continue (57CE0F15h)
57CE0EFE push 101h
57CE0F03 mov eax,dword ptr [ebx+esi*4+8]
57CE0F07 call _NLG_Notify (57CE0F55h)
57CE0F0C mov eax,dword ptr [ebx+esi*4+8]
57CE0F10 call _NLG_Call (57CE0F74h)

2
Are you sure this is the complete & actual code?John Dibling
Yes, thats where VS2010 debugger stops and shows the exceptionxend
So you are calling HandleMessages() on a good object instance?Arnold Spence
off-topic but please don't mix BOOL and bool.tenfour
Your "if (PeekMessage..." should probably be a "while (PeekMessage..." otherwise posted messages are going to queue up and may overflow the message queue, which can be very bad. -- At least, I am assuming there's no good reason that you are dispatching all sent messages and at most one posted message. In situations like this you normally want to either process all queued messages or none of them; almost never would you only want to process the first one and leave the others.Leo Davidson

2 Answers

0
votes
  • Show us your call stack. If it's crashing in msvcr100d.dll, then it's happening outside of PeekMessage (before or after the call). you should have good debugging info for this.
  • Take a look at the this pointer if applicable
  • do a rebuild all
  • Step into the disassembly
0
votes

I don't think the callstack you posted is quite sufficient to make anything out from it.

Is there a chance you could be calling HandleMessages() in response to a message? This could result in recursion / stack exhaustion.