[msw 2.8.7] Problem saving application settings when system
is shut down
Eric Jensen
ml at j-dev.de
Thu Apr 17 13:19:27 PDT 2008
Hello Vadim,
Thursday, April 17, 2008, 12:53:37 AM, you wrote:
VZ> Hmm, this is still pretty bad then as plenty of cleanup code (at least
VZ> dtor of wxApp and also dtors of all the global objects) is still not being
VZ> executed. I wonder if we can work around this by creating a dummy window in
VZ> wxApp::OnEndSession() (not a wxWindow as it would be destroyed too, but
VZ> just call ::CreateWindow())? If this fails (because I can imagine Windows
VZ> refusing to create windows during shutdown) we'd have to somehow avoid the
VZ> destruction of the existing windows, e.g. maybe by setting their m_hWnd
VZ> member to NULL from OnEndSession().
VZ> But before embarking on this, could you please test if the simple solution
VZ> of calling CreateWindow() works by chance?
just creating a dummy window did not work. Even creating a dummy
wxFrame in wxApp::OnEndSession() did not change the behavior. Which
confused me a bit, cause i'm still not 100% sure what actually
triggers killing the process.
Your second idea worked though. Here is what we have now:
void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
{
//if(GetTopWindow()) GetTopWindow()->Close(true);
// Windows will terminate the process soon after we
// return from WM_ENDSESSION handler anyhow, so make
// sure we at least execute our cleanup code before
if(wxTopLevelWindows.GetCount()>0) {
wxTopLevelWindows[0]->SetHWND(NULL);
}
const int rc = OnExit();
wxEntryCleanup();
// calling exit() instead of ExitProcess() or not doing
// anything at all and being killed by Windows has the
// advantage of executing the dtors of global objects
exit(rc);
}
Saving the old HWND and calling ::DestroyWindow() on it later does not
work (leads to a crash).
I'll do some more testing tomorrow.
Regards,
Eric
More information about the wx-users
mailing list