C Program Hangs inside GetMessage

2.6k views Asked by At

Our program hangs in the customer's machine (mostly in Windows 7).

The program is a client that connects to our server in a different machine. It is a C program with Win32 programming graphical interface.

Symptom: While executing our client application at random, it suddenly turns whitish and the dialog box "Application has stopped responding" appears, with two options: "close the application", "wait for the application to respond" etc. The customer computer says AppHang-B1.

We were not able to reproduce this problem in our systems. But once I reproduced the issue and took a crash dump.

The call stack says the following.

0012fa20 76accde0 76ac18d9 0012fcb0 00000000 ntdll!KiFastSystemCallRet
0012fa24 76ac18d9 0012fcb0 00000000 00000000 user32!NtUserGetMessage+0xc
0012fa48 00442dfc 0012fcb0 00000000 00000000 user32!GetMessageA+0x8d
0012fef8 00469b87 00400000 00000000 0334efed OurApp32!WinMain+0x12ec     [e:\mswnt\api55a\OurAppFolder\term\wbtmain.c @ 1350]
0012ff88 7589ee1c 7ffde000 0012ffd4 774237eb OurApp32!__tmainCRTStartup+0x113 [f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c @ 263]
0012ff94 774237eb 7ffde000 7eb0a7fe 00000000 kernel32!BaseThreadInitThunk+0xe
0012ffd4 774237be 00469bf2 7ffde000 00000000 ntdll!__RtlUserThreadStart+0x70
0012ffec 00000000 00469bf2 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b

Source code at the crash below. Note that it hangs at the GetMessage line.

  /* Handle messages - until were done */
  while (GetMessage(&msg,NULL,0,0)) { /* CRASH POINTS HERE */
     MenuWindow =  GetAccelerators(&msg);
     if (!TranslateAccelerator(MenuWindow.hWnd, MenuWindow.WinAccel, &msg)) {
        if ((MenuWindow.hWnd != 0 && MenuWindow.hWnd != hMainWnd) ||
           !TransmitFromMain(&msg)) { /* Screen to avoid key translation )*/
              TranslateMessage(&msg);    /* Translates virtual key codes    */
              DispatchMessage(&msg);     /* Dispatches message to window    */
        }
     }
  }

Local variables from windbg

hInstance   0x00400000 struct HINSTANCE__ * 0012ff00
hPrevInstance   0x00000000 struct HINSTANCE__ * 0012ff04
lpCmdLine   0x0334efed "-dMapper.msf"   0012ff08
nCmdShowz   0n1 0012ff0c
Alertmsg    char [256] ""   0012fdf0
bstatus 0n1 0012fef4
hData   0x045b29c8  0012fbac
hTDC    0xc6013534 struct HDC__ *   0012fccc
   i    0n39    0012fdec
lpCtrlData  0x045b29c8 struct ctrldata *    0012fba8
msg struct tagMSG   0012fcb0
 hwnd   0x001e0fe4 struct HWND__ *  0012fcb0
 message    0x325   0012fcb4
 wParam 0   0012fcb8
 lParam 0n0 0012fcbc
 time   0x9ee0b98   0012fcc0
 pt struct tagPOINT 0012fcc4
MsgHdr  char [256] ""   0012fcd0
scm struct CHARMETRIC   0012fdd4
sectionname char [256] "MPC"    0012fbb0

Any ideas why is it hanging? I was not able to get any information on msg->message 0x325

Thanks in advance


Some more information and answers to the questions below

Thanks for the replies Yes I have to change the GetMessage loop into something like

 while ( (ret = GetMessage(&msg,NULL,0,0) != 0 ) {
      if (ret == -1)
      {

I will be doing that

@Lundin Its not a multi threaded application.

Some more info on the Hang ... the Hang happens mostly when we Alt Tab from other applications into our Client. although it may happen at any time ... Any insight on what the msg 0x325 might be ?

0

There are 0 answers