First off, change your case statement in your procedure function to:

case WM_DESTROY:
case WM_CLOSE:
get_second_time();
PostQuitMessage(0);
break;

This way your get_second_time() function will get called regardless of how your function is closing. Second, you try to open a file in get_second_time(). This can be a problem in NT OS's (NT 4, win2000, XP and all new OS's), because once the system start's it's shutdown, the OS won't allow new files to be opened.

There are 2 solutions. At least one of these will work (in my experience, I've used both). First, always keep the file you are logging to open. This way, all your get_second_time() routine needs to do is output the string and close the file, which should be allowed on shutdown.

Second, and more complicated is to respond to the WM_QUERYENDSESSION message. This message is sent to all programs when windows is told to shutdown. If you return FALSE then the windows shutdown is halted. Now you can accomplish any tasks you need to finish, and then reinitiate the shutdown using ExitWindowsEx() when your done.

Hope this info helps!

- Kino