none
VC++ application hangs while changing language using short cut keys (Left ALT + SHIFT) RRS feed

  • Question

  • Hello

    We have a Visual C++ application running in Windows XP. Our application will be become "Not Responding" on typing some characters in the dialog edit control and by simulatenously
    changing the XP language(using shortcut key Left ALT + SHIFT)

    On debugging the application in VS2008 i could found that the control is not returning from
    following MFC code

    LRESULT CWnd::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
    {
        if (m_pfnSuper != NULL)
     --->    return ::CallWindowProc(m_pfnSuper, m_hWnd, nMsg, wParam, lParam);

    Watch information
    -----------------------------
            m_pfnSuper    0x7e43b3ec _EditWndProcA@16    long (HWND__ *, unsigned int, unsigned int, long)*
            nMsg    80    unsigned int
            wParam    1    unsigned int
            lParam    135464979    long

    Full Call stack information
    --------------------------------------------

              ntdll.dll!_KiFastSystemCallRet@0()    
         user32.dll!_NtUserMessageCall@28()  + 0xc bytes   
         user32.dll!_EditWndProcA@16()  + 0xd5 bytes   
         user32.dll!_InternalCallWinProc@20()  + 0x28 bytes   
         user32.dll!_UserCallWinProcCheckWow@32()  + 0xb7 bytes   
         user32.dll!_CallWindowProcAorW@24()  + 0x51 bytes   
         user32.dll!_CallWindowProcA@20()  + 0x1b bytes   
    >    mfc90d.dll!CWnd::DefWindowProcA(unsigned int nMsg=80, unsigned int wParam=1, long lParam=135464979)  Line 1043 + 0x20 bytes    C++
         mfc90d.dll!CWnd::WindowProc(unsigned int message=80, unsigned int wParam=1, long lParam=135464979)  Line 1756 + 0x1c bytes    C++
         mfc90d.dll!AfxCallWndProc(CWnd * pWnd=0x04c17f38, HWND__ * hWnd=0x00281598, unsigned int nMsg=80, unsigned int wParam=1, long lParam=135464979)  Line 240 + 0x1c bytes    C++
         mfc90d.dll!AfxWndProc(HWND__ * hWnd=0x00281598, unsigned int nMsg=80, unsigned int wParam=1, long lParam=135464979)  Line 403    C++
         mfc90d.dll!AfxWndProcBase(HWND__ * hWnd=0x00281598, unsigned int nMsg=80, unsigned int wParam=1, long lParam=135464979)  Line 441 + 0x15 bytes    C++
         user32.dll!_InternalCallWinProc@20()  + 0x28 bytes   
         user32.dll!_UserCallWinProcCheckWow@32()  + 0xb7 bytes   
         user32.dll!_DispatchMessageWorker@8()  + 0xdc bytes   
         user32.dll!_DispatchMessageA@4()  + 0xf bytes   
         mfc90d.dll!AfxInternalPumpMessage()  Line 183    C++
         mfc90d.dll!CWinThread::PumpMessage()  Line 900    C++
         mfc90d.dll!CWinThread::Run()  Line 629 + 0xd bytes    C++
         mfc90d.dll!CWinApp::Run()  Line 865    C++
         mfc90d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00151f02, int nCmdShow=1)  Line 47 + 0xd bytes    C++
         OurApplication.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00151f02, int nCmdShow=1)  Line 34    C++
         OurApplication.exe!__tmainCRTStartup()  Line 578 + 0x35 bytes    C
         OurApplication.exe!WinMainCRTStartup()  Line 403    C
         kernel32.dll!_BaseProcessStart@4()  + 0x23 bytes   


    Please help !

    Thanks in advance
    Harikrishnan
    Monday, April 27, 2009 10:43 AM

All replies

  • Hi, Harikrishnan

    Is your application multi-thread?  It sounds that the system is waiting for the reply of WM_IME_SELECT but no procedure for it in the thread.
    Please tell us some details about the threads.

    And please:
    1. Change to the each input language by mouse to check whether it still hands.
    2. Check your application, is there any place use SendMessage to communicate between the threads.

    Sincerely!
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, April 29, 2009 8:20 AM
  • Hi Harikrishnan,

    Is it works?  We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by editing your initial post and click the button "Change Type" at the top of the post. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

    Regards,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 4, 2009 2:32 AM
  • Hi Wesley,

    Sorry for the late reply! Still the application becomes "Not Responding" while i change the locale. I am attaching below some additional information, hope this will make the issue clear.

    1. Change to the each input language by mouse to check whether it still hands.

     I tried above, the application still hangs.

    2. Check your application, is there any place use SendMessage to communicate between the threads.

    No, the application is apartment threaded, since we have only one thread for the UI (But internally for some other process like file read, write i depend upon other threads). Also I put a break point on MyAppilc::PreTranslateMessage() and try debugging.

    I could found that the last message the application received before going to "Not Responding" state is "WM_INPUTLANGCHANGEREQUEST"

    One more point is the project build with multi byte character set turned on.

    Thanks in advance,
    Harikrishnan
    Monday, May 4, 2009 10:01 AM
  • Hello,

    Thanks for your useful information, so, seems the DefWindowProc hangs when handling the WM_INPUTLANGCHANGEREQUEST message.  If possible, would you please send me a sample to reproduce it?  You could upload it to here: http://www.mediafire.com/ and tell me the download site.
    And you could try to handle the message WM_INPUTLANGCHANGEREQUEST in the code, to figure out which part cause the hanging, according to the MSDN, we can handle it like:

    case WM_INPUTLANGCHANGEREQUEST:
        {
            if(GetKeyboardLayout(0) == (HKL)lParam)
                return 0;
            UINT count = GetKeyboardLayoutList(0,NULL);
            if(count == 0) return 0;
            HKL* lpList = new HKL[count];
    
            count = GetKeyboardLayoutList(count,lpList);
            BOOL bFound = FALSE;
            for(int i = 0; i < count; i++)
            {
                if((HKL)lParam == lpList[i])
                {
                    bFound = TRUE;
                    break;
                }
            }
            if(lpList)
            {
                delete[] lpList;
                lpList = NULL;
            }
            if(!bFound)
            {
                CString sID;
                sID.Format("%08x",lParam);
                LoadKeyboardLayout(sID,KLF_ACTIVATE);
            }
            else
            {
                 ActivateKeyboardLayout((HKL)lParam,KLF_SETFORPROCESS);
            }
        }

    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, May 5, 2009 9:36 AM
  • Hi Wesley,

    Thanks, i failed to reproduce the issue within a sample application and i am still working on it.

    Meanwhile i can give you some more useful information which i  tried by adding the above code to our application MyApp::PreTranslateMessage (MyApp is the main window thread which derived from CWinApp).

    Now the message call seems to be not returning after last point  in the code above

     -->  ActivateKeyboardLayout((HKL)pMsg->lParam,KLF_SETFORPROCESS);

    Please find call stack in debug and other information attached

    Thread Window:-
    -----------------------
    0    >    2660    Main Thread    Main Thread    AfxPreTranslateMessage    Normal    0

    Call Stack:-
    --------------------
              ntdll.dll!_KiFastSystemCallRet@0()    
         user32.dll!_NtUserActivateKeyboardLayout@8()  + 0xc bytes   
         mfc90d.dll!AfxPreTranslateMessage(tagMSG * pMsg=0x00157788)  Line 252 + 0x11 bytes    C++
         mfc90d.dll!AfxInternalPumpMessage()  Line 178 + 0x18 bytes    C++
         mfc90d.dll!CWinThread::PumpMessage()  Line 900    C++
         mfc90d.dll!CWinThread::Run()  Line 629 + 0xd bytes    C++
         mfc90d.dll!CWinApp::Run()  Line 865    C++
         mfc90d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00151f02, int nCmdShow=1)  Line 47 + 0xd bytes    C++
         App.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00151f02, int nCmdShow=1)  Line 34    C++
    >    App.exe!__tmainCRTStartup()  Line 578 + 0x35 bytes    C
         App.exe!WinMainCRTStartup()  Line 403    C
         kernel32.dll!7c817067()    
         [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]   


    Disassembly for ntdll.dll!_KiFastSystemCallRet@0()
    -----------------------------------------------------------
    _KiFastSystemCallRet@0:
    7C90E4F4  ret             
    7C90E4F5  lea         esp,[esp]
    7C90E4FC  lea         esp,[esp]

    where     esp    =  1244440 unsigned long

    Regards,
    Harikrishan
    Thursday, May 7, 2009 3:33 PM
  • Hello,

    Sorry for too late reply.

    Today i got one new clue regarding this issue, application works fine if i unchecked East Asian language option from Windows XP Control Panel-> Regional and Language Options.
    On searching net i could found that this East Asian language option in Windows XP has got some relationship with Input Method Editors(IME), but it is not advisable for end users to unistall this before running an application.

    I am attaching here with the message flow for my application with and without EA language support.

    ----------------------------------
    Without EA language support
    ----------------------------------
    <01021> 000D11FC P message:0x0118 [Unknown] wParam:0000FFFF lParam:BF8C391A
    <01022> 000D11FC P WM_SYSKEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:1 fRepeat:0 fUp:0
    <01023> 000D11FC P WM_INPUTLANGCHANGEREQUEST fSysCharset:True hkl:08130813
    <01024> 000D11FC P WM_SYSKEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:1 fRepeat:1 fUp:1
    <01025> 000D11FC P WM_INPUTLANGCHANGEREQUEST fSysCharset:True hkl:08130813
    <01026> 000D11FC S WM_INPUTLANGCHANGE charset:0 hkl:08130813
    <01027> 000D11FC R WM_INPUTLANGCHANGE
    <01028> 000D11FC P WM_KEYUP nVirtKey:VK_MENU cRepeat:1 ScanCode:38 fExtended:0 fAltDown:0 fRepeat:1 fUp:1
    No problems !

    ----------------------------------
    With EA language support
    ----------------------------------
    <00369> 00030C0C P message:0x0118 [Unknown] wParam:0000FFFF lParam:BF8C391A
    <00370> 00030C0C P WM_SYSKEYDOWN nVirtKey:VK_MENU cRepeat:1 ScanCode:38 fExtended:0 fAltDown:1 fRepeat:0 fUp:0
    <00371> 00030C0C P WM_SYSKEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:1 fRepeat:0 fUp:0
    <00372> 00030C0C P WM_INPUTLANGCHANGEREQUEST fSysCharset:True hkl:08130813
    <00373> 00030C0C P WM_KEYUP nVirtKey:VK_MENU cRepeat:1 ScanCode:38 fExtended:0 fAltDown:0 fRepeat:1 fUp:1
    <00374> 00030C0C P WM_INPUTLANGCHANGEREQUEST fSysCharset:True hkl:08130813
    <00375> 00030C0C S ...........WM_IME_NOTIFY dwCommand:00000001 dwData:00000000
    <00376> 00030C0C R ...........WM_IME_NOTIFY
    <00377> 00030C0C S ...........WM_IME_NOTIFY dwCommand:00000002 dwData:00000000
    <00378> 00030C0C R ...........WM_IME_NOTIFY
    Application hangs!

    ----------------------------------

    I even tried out by freezing all other threads and enabling the main UI thread only, but still this issue persists.

    As per previous comment from Wesley "It sounds that the system is waiting for the reply of WM_IME_SELECT but no procedure for it in the thread."
    This is 100% true.
    But i am wondering why suddenly after a point in code that too in ntdll.dll there is no more procedure for it in the thread even though there is only one thread enabled in visual studio.

    Please help!

    Regards,
    Harikrishnan
    Tuesday, June 9, 2009 2:45 PM
  • hi Harikrishnan and Wesley,

    Do you guys already solve this problem? The same problem also happens in my application... The call stack and process are very similar to Harikrishnan's, so I did not post the call stack.

    I have no idea how to solve it.... Please help

     

    Joe

    Monday, August 9, 2010 6:06 AM
  • Hi,

    I experienced same problem in my QT application on Windows XP. Disabling IME support by calling ImmDisableIME fixes the issue.

    Aleksey

    • Proposed as answer by Gnilly Boy Monday, September 27, 2010 2:38 PM
    Monday, September 27, 2010 2:38 PM
  • Hello All

    ImmDisableIME may work but it will also disable the functionality. The root cause partially

    as sated by Wesley Yao. i.e.handling WM_INPUTLANGCHANGEREQUEST

    Windows OS expects all GUI threads to process/Respond WM_INPUTLANGCHANGEREQUEST message and process hangs until all the gui thread process.

    Generally this issue will not come up if we have the familiar message loop in our thread function.

    In our case, we have a worker thread which doesn't have message loop but during a background operation this worker thread become GUI thread by creating progress dialog, but still this one doesn't have message loop

    And the issues is resolved by implementing message loop for this worker thread

    FYI- I am also from Network System, The solution actually fixed the original issue posted by Harikrishnan and thought of sharing since this may help others in case...


    • Edited by Antony_T Friday, November 25, 2011 12:50 PM
    Friday, November 25, 2011 12:49 PM