应用是多线程的
但是都没有调用非法代码
用CArray <...>管理对象指针
只在一处(单一线程)中释放该对象实例
运行到CWnd::~CWnd调用DestroyWindow时出问题
但是查m_hWnd有效
哪位高手援手,不胜感激!!!

解决方案 »

  1.   

    如果在一个线程中创建的CWnd对象是不能到另一个线程中去释放的。
    在说具体一点你的CWnd创建,引用与释放的地方?
      

  2.   

    To Bugn:
    我的CWnd对象是在子线程中new的,但是Create在主线程中
    而我也在主线程中delete对象,这样也不对?
    难道必须new/Create/delete 都处于同一线程?
      

  3.   

    请教:
    多线程中使用CWnd对象具体有那些限制?
      

  4.   

    我已经将实例的new/Create/delete全移到主线程中了
    结果还是断言错经过详细跟踪,发现是执行到
    BOOL CWnd::DestroyWindow()
    {
    if (m_hWnd == NULL)
    return FALSE; CHandleMap* pMap = afxMapHWND();
    ASSERT(pMap != NULL);
    CWnd* pWnd = (CWnd*)pMap->LookupPermanent(m_hWnd);
    #ifdef _DEBUG
    HWND hWndOrig = m_hWnd;
    #endif#ifdef _AFX_NO_OCC_SUPPORT
    BOOL bResult = ::DestroyWindow(m_hWnd);
    #else //_AFX_NO_OCC_SUPPORT
    BOOL bResult;
    if (m_pCtrlSite == NULL)
    bResult = ::DestroyWindow(m_hWnd);
    else
    bResult = m_pCtrlSite->DestroyControl();
    #endif //_AFX_NO_OCC_SUPPORT // Note that 'this' may have been deleted at this point,
    //  (but only if pWnd != NULL)
    if (pWnd != NULL)
    {
    // Should have been detached by OnNcDestroy
    #ifdef _DEBUG
    ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);
    #endif
    }
    else
    {
    #ifdef _DEBUG
    ASSERT(m_hWnd == hWndOrig); //HERE!!!!!ASSERT FAILED!
    #endif
    // Detach after DestroyWindow called just in case
    Detach();
    }
    return bResult;
    }
    中的ASSERT(m_hWnd == hWndOrig);时出错
    请问这是为什么?该如何解决?
    急!!!
      

  5.   

    我已经将实例的new/Create/delete全移到主线程中了
    结果还是断言错经过详细跟踪,发现是执行到
    BOOL CWnd::DestroyWindow()
    {
    if (m_hWnd == NULL)
    return FALSE; CHandleMap* pMap = afxMapHWND();
    ASSERT(pMap != NULL);
    CWnd* pWnd = (CWnd*)pMap->LookupPermanent(m_hWnd);
    #ifdef _DEBUG
    HWND hWndOrig = m_hWnd;
    #endif#ifdef _AFX_NO_OCC_SUPPORT
    BOOL bResult = ::DestroyWindow(m_hWnd);
    #else //_AFX_NO_OCC_SUPPORT
    BOOL bResult;
    if (m_pCtrlSite == NULL)
    bResult = ::DestroyWindow(m_hWnd);
    else
    bResult = m_pCtrlSite->DestroyControl();
    #endif //_AFX_NO_OCC_SUPPORT // Note that 'this' may have been deleted at this point,
    //  (but only if pWnd != NULL)
    if (pWnd != NULL)
    {
    // Should have been detached by OnNcDestroy
    #ifdef _DEBUG
    ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);
    #endif
    }
    else
    {
    #ifdef _DEBUG
    ASSERT(m_hWnd == hWndOrig); //HERE!!!!!ASSERT FAILED!
    #endif
    // Detach after DestroyWindow called just in case
    Detach();
    }
    return bResult;
    }
    中的ASSERT(m_hWnd == hWndOrig);时出错
    请问这是为什么?该如何解决?
    急!!!
      

  6.   

    to bugu:
    还是一样啊,在CWnd::DestroyWindow()的ASSERT(m_hWnd == hWndOrig);
    语句处断言失败这个类继承了自CWnd继承的类,
    class A:public CWnd
    {
    ....
    ;
    };
    class B:public A
    {
    ;
    };
    不知道是不是与此有关系
    因为我另一个只一级继承的类工作正常
    为什么呢
      

  7.   

    其他的类工作基本正常了
    就是二级继承的类DestroyWindow失败我认真看了看代码
    可能跟类定义中的DECLARE_DYNCREATE有关系
    class CDevice:public CWnd{
    DECLARE_DYNCREATE(CSerialPort)
    .....................
    };
    class CSerialPort:public CDevice
    {
    DECLARE_DYNCREATE(CSerialPort)
    .....................
    };
    不过我确实需要运行类类型支持
    我该怎么办?
      

  8.   

    CWnd是不能在多线程间传递的
      

  9.   

    我看不象是这的问题,你的BEGIN_MESSAGE_MAP(CSerialPort, XXX)中,XXX是什么?