In trying to find the root cause of a problem

Discussion in 'MFC' started by KyungHee Kim, Nov 30, 2009.

  1. KyungHee Kim

    KyungHee Kim New Member

    Joined:
    Nov 30, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    In our application, we have property page created in the main. When the use click the tab of the page, its handle is passed to DLL and a window is created for the page in DLL and the handle passed to DLL become its parent. When the App exit, the window gets destroyed and crash occurs because the window handle map is NULL. In this sceanario, i like to know what is the root cause of the crash? (if i stated the problem clearly). I would greatly apprecite if any expert explains the cause of problem. And how to go about getting infomation in resolving the problem.
     
  2. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    Have you tried it in the debugger to see where the crash occurs?
     
  3. KyungHee Kim

    KyungHee Kim New Member

    Joined:
    Nov 30, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Yes, i know exactly where it crashes:

    First the following routine gets called with hWnd==The Property Page in our main App, thus Create() and SetParent() below are executed.

    Upon App Exit, this is called as SetSPWnd(NULL) which in turn DetroyWindow() gets executed - here crash occurs - Map (Handle) is NULL.

    i like to know whether it is illegal to set handle (in Main APP) as a parent to a window that is being created in DLL and later destroy in DLL. What mechnism does Windows provide a situaltion like ours - a legal way so that it does not end up crashing.

    If i create the window in our Main App and destroy in the same place, i do not have any problem. However we would like to create the window(dialog) in DLL and somehow detach the parent and destory cleanly. i tried with Detach Getparent()->Detach(). no avail - because i do not have full understanding of Windows.... At least i like to know what we are doing is illegal because etc.... AND like to know if there is a way (legal) to do...

    ( ---with much appreciation)
    Code:
     
    /*****************************************************************************/
    void CDevWinApp::SetSPWnd(
            HWND hWnd)
    {
        m_hSPWnd = hWnd;
        if ( m_pSPDlg == NULL )
        {
            return;
        }
        if ( NULL != m_pSPDlg->m_hWnd )
        {
            if ( hWnd )
                m_pSPDlg->SetParent(CWnd::FromHandle(hWnd));
            else if ( m_pSPDlg->m_hWnd )
                m_pSPDlg->DestroyWindow();
        }
        else
        {
            if ( NULL != hWnd )
            {
                ASSERT(m_pSPDlg);
                ASSERT(m_nSPDlg>0);
                if ( m_pSPDlg && m_nSPDlg )
                {
                    m_pSPDlg->Create(m_nSPDlg,CWnd::FromHandle(hWnd));
                    m_pSPDlg->SetParent(CWnd::FromHandle(hWnd));
                }
            }
        }
    }
     
    Last edited by a moderator: Dec 1, 2009
  4. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    I'm not really sure what you are doing, but DestroyWindow is usually problematic. Have you tried just posting a WM_QUIT to the window instead? That should cleanly end the window and it will let its parent know that it is exiting cleanly too, so you may not even have to detach.
     
  5. KyungHee Kim

    KyungHee Kim New Member

    Joined:
    Nov 30, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    My quesiton is that is it legal to send a window handle in EXE to DLL as a parent.

    If it is, how to delete the window in DLL of which parent handle was created in main APP EXE, not DLL.

    Regards.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Sending Window Handle is fine but then who would do the cleaning should be handled carefully
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice