PeekMessage() throws an unhandled exception (access violation)

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)


  • 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

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

    链接地址: http://www.djcxy.com/p/64600.html

    上一篇: x86自旋锁使用cmpxchg

    下一篇: PeekMessage()抛出未处理的异常(访问冲突)