Error - Object Deleted Before Window Was Destroyed
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to delete a pointer to a modeless dialog in WTL up vote 2 down vote favorite in MainDlg Function LRESULT CMainDlg::OnDo(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { CMyDlg* dlg = new CMyDlg;// it could be CMainDlg member var //dlg.pMain = this; // i want to SendMessage(pMain.m_hWnd...) in CMyDlg...but it don't // work... dlg->Create(m_hWnd); dlg->ShowWindow(SW_SHOW); return 0; } in CMyDlg class CMyDlg : public CDialogImpl
Sent: Wednesday, August 07, 2002 1:29 PM > To: wtl-hHKSG33TihhbjbujkaE4pw@xxxxxxxxxxxxxxxx > Subject: [wtl] Re: Closing the main window when last object destroyed > > I like the static instance pointer to CMainFrame. I'm a little > chagrined that I didn't think of it myself. :) > > The Lock/Unlock solution for releasing the Module does not work for > me. I get an assert failure in atlwin.h (line 2748) > ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Object deleted before > window was destroyed\n")); I was afraid of that. It is referring to http://stackoverflow.com/questions/11336873/how-to-delete-a-pointer-to-a-modeless-dialog-in-wtl the fact that the CMainFrame destructor is being called before the window received a WM_DESTROY message (because the WM_QUIT message caused the message loop to end and the CMainFrame object to go out of scope). Usually WM_QUIT is posted from a window's WM_DESTROY handler, so since it was posted from elsewhere, WM_DESTROY was never sent to the window. So you http://osdir.com/ml/windows.wtl/2002-08/msg00010.html need a call to DestroyWindow before(after?) the WM_QUIT message. For example, your CMainFrame could override DestroyWindow and call CWindow::DestroyWindow when the module lock count goes to 1. This will cause a WM_DESTROY message to be sent when the last object is released. CMainFrame::DestroyWindow() { // Really destroy the window iff called from // the last remaining object if (_Module.GetLockCount() == 1) { CWindow::DestroyWindow(); } } Then in your logger object final release: CLoggerObject::FinalRelease() { CMainFrame::GetFrame()->DestroyWindow(); } Or you could try to call DestroyWindow *after* the message loop returns. I don't know if this will work or not because I don't know if a message pump has to be running for WM_DESTROY to be delivered by DestroyWindow. Try this: int Run(...) { CMessageLoop theLoop; _Module.AddMessageLoop(&theLoop); CMainFrame mainWnd; mainWnd.Create(...) theLoop.Run() mainWnd.DestroyWindow(); _Module.RemoveMessageLoop(&theLoop); } > > I'm not exactly sure as to which object it is referring. > Interestingly enough, this is the same result that I get if I > maintain a static refcount in my logger object, and post a WM_QUIT > message to the mainframe when it
från GoogleLogga inDolda fältSök efter grupper eller meddelanden
JavaScript ASP HTML(CSS) HTML5 Apache 开发语言/框架 Delphi VC/MFC VB C/C++ C++ Builder 其他开发语言 数据库开发 MS-SQL Server Oracle PowerBuilder Informatica 其他数据库开发 硬件/嵌入式开发 嵌入开发(WinCE) 驱动开发/核心开发 硬件设计 单片机/工控 汇编语言 VxWorks开发 Linux/Unix社区 系统维护与使用区 应用程序开发区 内核源代码研究区 驱动程序开发区 CPU和硬件区 论坛帮助 论坛牛人 论坛地图 专家问答 << >> CSDN > CSDN论坛 > C/C++ > C++ 语言 返回列表 管理菜单 置顶 推荐 锁定 移动 编辑 删除 帖子加分 帖子高亮 结帖 发帖 回复 关注 sjjwind ATL,直接调用DestroyWindow,触发断言:Object deleted before window was destroyed。 [问题点数:40分] 快速回复 只显示楼主 关注帖子 ATL,直接调用DestroyWindow,触发断言:Object deleted before window was destroyed。 [问题点数:40分] 不显示删除回复 显示所有回复 显示星级回复 显示得分回复 只显示楼主 收藏 取消关注 关注 sjjwind sjjwind 本版等级: 本版专家分:709 结帖率:95% 楼主 发表于: 2014-05-11 20:37:13 atl 首先说明,有一个窗口类A继承自WindowImpl类。 我是在WM_KILLFOCUS里面调用DestroyWindow,然后就触发了这个断言: virtual~CWindowImplRoot() { #ifdef_DEBUG if(m_hWnd!=NULL) //shouldbeclearedinWindowProc { ATLTRACE(atlTraceWindowing,0,_T("ERROR-Objectdeletedbeforewindowwasdestroyed\n")); ATLASSERT(FALSE); } #endif//_DEBUG } 然后google找解决方法,提供的方法是重写WindowImplRoot的OnFinalMessage,但是我重写这个方法之后,根本就不会触发这个函数。然后也试过其他的关闭窗口方法,都是触发这个断言。 但是如果别的窗口调用这个窗口类的DestroyWindow,就不会触发断言。 请问这种情况应该怎么解决。 更多 分享到: 对我有用[0] 丢个板砖[0] 引用 | 举报 | 编辑 删除 管理 回复次数:5 相关知识库: 深度学习 React Native iOS 直播技