tags:

views:

82

answers:

2

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)

A: 

Is it happening on the first invocation? Does try/catch around it help? Also, if there is no specific reason to use PeekMessage(), why not use GetMessage() instead?

Tareq A. Siraj
There is a reason for PeekMessage() as i invoke it in a loop where i need this non-blocking version
xend
A: 
  • 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
tenfour
will do when i get home from work :)
xend
Alright, added the stack to the first post
xend