-
Saving data on shutdown
Hello,
My program currently writes data to the registry when it is closed (Either by closing its window or using the Task Manager). However, it doesn't seem to do it when the computer is shutdown. My WinMain loop calls the functions necessary:-
Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND hwndMain;
MSG msg;
g_hInstance = hInstance;
Registry(FALSE); // Load
if (!CreateMainWindow(&hwndMain))
return FALSE;
ShowWindow(hwndMain, nShowCmd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Registry(TRUE); // Save
return msg.wParam;
}
And in my WindowProc:-
Code:
case WM_CLOSE:
case WM_ENDSESSION:
{
DestroyWindow(hwnd);
break;
}
case WM_DESTROY:
{
WSACleanup();
PostQuitMessage(0);
break;
}
This leads me to believe that either the WM_DESTROY message isn't being sent, or the function call after the message pump in WinMain is being side-stepped for some reason. Or perhaps the registry is locked up for the night before I can write to it?
-
Have you tried putting the registry function in the WM_DESTROY event?
-
How about writing a logfile to disk so you can see what gets called and what throws errors ?
-
When windows is shutting down I believe it does send a WM_CLOSE, do why not change your code accordingly?