Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   In trying to find the root cause of a problem (http://www.go4expert.com/forums/trying-root-cause-t20241/)

KyungHee Kim 1Dec2009 00:09

In trying to find the root cause of a problem
 
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.

Gene Poole 1Dec2009 01:36

Re: In trying to find the root cause of a problem
 
Have you tried it in the debugger to see where the crash occurs?

KyungHee Kim 1Dec2009 06:23

Re: In trying to find the root cause of a problem
 
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));
            }
        }
    }
}


Gene Poole 1Dec2009 20:35

Re: In trying to find the root cause of a problem
 
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.

KyungHee Kim 4Dec2009 22:23

Re: In trying to find the root cause of a problem
 
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.

shabbir 5Dec2009 11:29

Re: In trying to find the root cause of a problem
 
Sending Window Handle is fine but then who would do the cleaning should be handled carefully


All times are GMT +5.5. The time now is 10:24.