[Haskell-cafe] Windows: how to perform cleanup actions when the console window closes
jo at durchholz.org
Fri Apr 6 08:46:09 UTC 2018
Am 06.04.2018 um 10:09 schrieb Peter Dedecker:
> Summary question and TLDR: how do I reliably perform cleanup actions in
> a Windows console program that is closed by the user by clicking the 'X'
> symbol in the window title bar?
You need to intercept the various events that may cause a console
windows to be closed; this is done via the Windows API call
https://stackoverflow.com/a/30843219/6944068 gives an overview, API doc
(you want to register a HandlerRoutine).
The default handler simply calls ExitProcess, bypassing all shutdown
activity of the runtime. That's why C++ guys complain that destructors
are not called.
I don't know how to register a Haskell function as a Windows callback,
that will have to be answered by somebody else.
More information about the Haskell-Cafe