Saving data on shutdown

This is a discussion on Saving data on shutdown within the Windows Programming forums, part of the Platform Specific Boards category; Hello, My program currently writes data to the registry when it is closed (Either by closing its window or using ...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266

    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?

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Have you tried putting the registry function in the WM_DESTROY event?

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    How about writing a logfile to disk so you can see what gets called and what throws errors ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    When windows is shutting down I believe it does send a WM_CLOSE, do why not change your code accordingly?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 06:43 AM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Saving Data
    By JoeJTaylor in forum C++ Programming
    Replies: 5
    Last Post: 04-22-2006, 09:06 PM
  4. C diamonds and perls :)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM
  5. Saving data
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-01-2002, 08:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21