From 9c564af18dc3faad8910bfe14b45ed4ab884d797 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 29 Feb 2020 15:35:08 +0100 Subject: Keep console alive when exiting as last process on Windows --- midimonster.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index d9a99d9..9cbc3a9 100644 --- a/midimonster.c +++ b/midimonster.c @@ -264,13 +264,27 @@ static fd_set fds_collect(int* max_fd){ } static int platform_initialize(){ -#ifdef _WIN32 + #ifdef _WIN32 WSADATA wsa; WORD version = MAKEWORD(2, 2); if(WSAStartup(version, &wsa)){ return 1; } -#endif + #endif + return 0; +} + +static int platform_shutdown(){ + #ifdef _WIN32 + DWORD processes; + if(GetConsoleProcessList(&processes, 1) == 1){ + fprintf(stderr, "\nMIDIMonster is the last process in this console, please press any key to exit\n"); + HANDLE input = GetStdHandle(STD_INPUT_HANDLE); + SetConsoleMode(input, 0); + FlushConsoleInputBuffer(input); + WaitForSingleObject(input, INFINITE); + } + #endif return 0; } @@ -346,7 +360,7 @@ int main(int argc, char** argv){ fds_free(); plugins_close(); config_free(); - return usage(argv[0]); + return (usage(argv[0]) | platform_shutdown()); } //load an initial timestamp @@ -433,6 +447,7 @@ bail: event_free(); plugins_close(); config_free(); + platform_shutdown(); return rv; } -- cgit v1.2.3