Error - Object Deleted Before Window Was Destroyed N
don't know tow to I fix this:assertion that I receive.---------------------------------------------------------------------#ifdef _DEBUGif(m_hWnd != NULL) // should be cleared inWindowProc{ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Objectdeleted before window was destroyed\n"));ATLASSERT(FALSE);}#endif //_DEBUG}---------------------------------------------------------------------I don't know how to: `cleared in WindowProc' or `Object deletedbefore window was destroyed' (I don't destroy MDIChild).How to I fix this?Thanks Alexander Nickolov 2004-12-10 20:40:50 UTC PermalinkRaw Message You forgot to destroy your window before you destroyedthe wrapper class instance. You typically destroy windowsvia DestroyWindow on the wrapper class.--=====================================Alexander NickolovMicrosoft MVP [VC], MCSDemail: ***@mvps.orgMVP VC FAQ: http://www.mvps.org/vcfaq=====================================Post by ReTfHi All,assertion that I receive.---------------------------------------------------------------------#ifdef _DEBUGif(m_hWnd != NULL) // should be cleared inWindowProc{ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Objectdeleted before window was destroyed\n"));ATLASSERT(FALSE);}#endif //_DEBUG}---------------------------------------------------------------------I don't know how to: `cleared in WindowProc' or `Object deletedbefore window was destroyed' (I don't destroy MDIChild).How to I fix this?Thanks 1 Reply 245 Views Switch to linear view Disable enhanced parsing Permalink to this page Thread Navigation ReTf 2004-12-10 11:55:00 UTC Alexander Nickolov 2004-12-10 20:40:50 UTC about - legalese Loading...
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 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 http://microsoft.public.vc.atl.narkive.com/DhdV5lWa/atltrace-atltracewindowing-0-t-error-object-deleted-before-window-was-destroyed-n 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 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 http://osdir.com/ml/windows.wtl/2002-08/msg00010.html 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 goes to zero. > > However, posting a WM_CLOSE message works just fine. Is there any > reason not to use this method? > Posting a WM_CLOSE should work fine. The default handler for WM_CLOSE usually calls DestroyWindow thus allowing the assert to be satisfied. Just make sure that you only post it when the last logger object is destroyed. You can use _Module.GetLockCount() to determine this as I did above. But IMO you should encapsulate that check in your main frame class rather than checking in the logger object's final release be
is a continuation of my message of the 2/19/01. I'm currently using a local server that manage a CWindowImpl. I have declare the http://computer-programming-forum.com/77-vc-atl/ee6c2d6d9b9cec30.htm window as being a singleton (using DECLARE_CLASSFACTORY_SINGLETON) so that there would only http://www.yqcomputer.com/125_512_1.htm be one instance of the server at any time. This at least allow me to share the window between different instance of the ATL object. I do have some issues. I can't create another window (since it already exist m_hWnd != 0 ) and since the class is error - a singleton it will keep sharing the same handle no matter what. Also i get this assert when i close the share window : ATL: ERROR - Object deleted before window was destroyed Which indicate that the CWindowImpl instance of the server gets deleted before the window is properly released. Is this because i force the window to be a error - object singleton? One solution i have right now is to use ::DestroyWindow() on the handle and then set the m_hWnd of the CWindowImpl to 0 to avoid the second destruction of the window. Don't know if that's very good to do. Thank you in advance. Francois Belair Sat, 09 Aug 2003 23:53:44 GMT #2 / 3 ATL: Object deleted before window was destroyed Fri, 19 Jun 1992 00:00:00 GMT Alexander Nickolo#3 / 3 ATL: Object deleted before window was destroyed CWindowImpl already has a DestroyWindow method. -- ===================================== Alexander Nickolov Microsoft MVP [VC], MCSD MVP VC FAQ: http://www.mvps.org/vcfaq ===================================== Quote:> Salutation, > This is a continuation of my message of the 2/19/01. > I'm currently using a local server that manage a CWindowImpl. I have declare > the window as being a singleton (using DECLARE_CLASSFACTORY_SINGLETON) so > that there would only be one instance of the server at any time. > This at least allow me to share the window between different instance of the > ATL object. > I do have some issues. I can't create ano
to host a webbrowser control in this program, and it's pretty much the same way as is explained in the AtlBrowser example. The following method is defined in the interface: [id(DISPID_SAYHELLO), helpstring("method SayHello")] HRESULT SayHello(); So that in an HTML page, we can use: to interact with the browser. However, it appeared that I found a bug in this mechanism. If I click this link once, everything is fine. But if I click this link for the second time (HRESULT SayHello() method is still being executed successfully), the host window will no longer receive WM_NCDESTROY and WM_DESTROY. So if I close the frame window, I'll see the following message in the output window: ERROR - Object deleted before window was destroyed Sometimes it comes with an assert message box too. I suppose it's a trace message in CWindowImpl complaining about the window object is being deleted while the window isn't destroyed yet. That's odd (in SayHello(), only MessageBox and trace APIs were used, I'm certainly not doing any weird stuff). The AtlBrowser example does cleanups in WM_NCDESTROY. So I tracked it down (by defining message macros) and discovered that WM_NCDESTROY and WM_DESTROY weren't received at the point of destroying. It doesn't happen when I click the link once. It only happens when I click it twice or more times. It happens to my program, and it happens to the AtlBrowser example. Any clues? -- He Shiming Top 1. AtlBrowser - ERROR - Object deleted before window was destroyed 2. ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Object deleted before window was destroyed\n")); Hi All, I receive this assertion, but I don't know tow to I fix this: assertion that I receive. --------------------------------------------------------------------- #ifdef _DEBUG if(m_hWnd != NULL) // should be cleared in WindowProc { ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Object deleted before window was destroyed\n")); ATLASSERT(FALSE); } #endif //_DEBUG } --------------------------------------------------------------------- I don't know how to: `cleared in WindowProc' or `Object deleted before window was destroyed' (I don't destroy MDIChild). How to I fix this? Thanks 3. modal/modeless WTL dialog - ERROR - Object deleted before window was destroyed 4. Object deleted before window was destroyed 5. Off Topic: use delete to destroy primitive/object types but memory is not freed 6. use delete to destroy primitive/object types but memory is not freed 7. Off Topic: use delete to destroy prim