spiegel-keyman/windows
Marc Durdin cb9d1589c2 fix(windows): make sure IdStackWindows finalizes after Vcl.Forms
Fixes #7690.

When kmshell.dpr is being shut down by Windows via `WM_ENDSESSION`, the
order of termination of units through `finalization` sections means that
`IdStackWindows` was finalizing while components were still depending on
it, causing a cascade of exceptions resulting eventually in the crash
visible in #7690.

We saw this when there were message loops before `Application.Run` had
ever been called. For example, message box/dialog, ShellExecute (yep...
this can do a `PeekMessage`), `THttpUploader` (which calls
`Application.ProcessMessages`) and probably others.

Ideally, it would be better to always call `Application.Run`, but it is
not safe to call `Application.Run` more than once, because it ends up
adding multiple `DoneApplication` exit procs, which would likely cause
other crashes.

I landed on the somewhat heavy-handed solution of adding
`IdStackWindows` to the start of the project `uses` list, ensuring it is
the last unit to be finalized -- importantly, before `Vcl.Forms`. A
better solution would be to find a way of ensuring that
`Application.Run` is called, just once, in all situations, but this is
likely to be hard to achieve. The shutdown sequence for Delphi apps is
so very, very fragile.
2022-11-11 13:03:47 +11:00
..
include chore(windows): move kmtip_guids.h and testkeymanfunctioning.h 2022-06-12 07:43:24 +10:00
src fix(windows): make sure IdStackWindows finalizes after Vcl.Forms 2022-11-11 13:03:47 +11:00