safe exit when console is closed on Windows (#1269)

This commit is contained in:
Roman Fomin 2023-11-20 11:02:49 +07:00 committed by GitHub
parent b3097103e6
commit ec600f80c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -17,12 +17,12 @@
//
//-----------------------------------------------------------------------------
#include <stdio.h>
#include "config.h"
#include "SDL.h" // haleyjd
#include "i_printf.h"
#include "i_system.h"
#include "m_argv.h"
#include "version.h"
@ -34,6 +34,13 @@
void D_DoomMain(void);
#if defined(WIN_LAUNCHER)
__declspec(dllexport) void Woof_Exit(void)
{
I_SafeExit(0);
}
#endif
#if defined(WIN_LAUNCHER)
__declspec(dllexport) int Woof_Main(int argc, char **argv)
#else

View File

@ -13,10 +13,25 @@
//
#include "SDL.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
__declspec(dllexport) extern int Woof_Main(int argc, char **argv);
__declspec(dllexport) extern void Woof_Exit(void);
BOOL CtrlHandler(DWORD event)
{
if (event == CTRL_CLOSE_EVENT)
{
Woof_Exit();
return TRUE;
}
return FALSE;
}
int main(int argc, char **argv)
{
SetConsoleCtrlHandler((PHANDLER_ROUTINE)(CtrlHandler), TRUE);
return Woof_Main(argc, argv);
}