I'm writing a very simple Delphi 2007 program that monitors system activities. The program just hooks a DLL procedure and has to simply wait until the system shutsdown since all the handling is done in the DLL callback. Is a windowless program since I even removed the {$APPTYPE CONSOLE} from the source. The code is very simple:
begin
try
// TODO -oUser -cConsole Main : Insert code here }
// If load sucessfull
If (LoadDLL ()) Then Begin
// Hook
_dllSetWindowsHookEx (LibHandle);
If (_dllHooked ()) Then Begin
Repeat
Until .......what?;
// Unhook
_dllUnhookWindowsHookEx ();
End;
// Release
UnloadDLL ()
End
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
end.
I checked this question and it seems that maybe this will work:
Repeat
Until GetSystemMetrics(SM_SHUTTINGDOWN) <> 0;
However it also seems that it will use a lot of CPU. Is there another PeekMessage/WaitForSingleObject like approach to properly quit the program at system shutdown?