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 shabbir; 1Dec2009 at 09:25.. Reason: Code blocks