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 --- backends/lua.c | 1 + midimonster.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/backends/lua.c b/backends/lua.c index 7d20fb1..955341a 100644 --- a/backends/lua.c +++ b/backends/lua.c @@ -457,6 +457,7 @@ static int lua_start(size_t n, instance** inst){ if(strcmp(data->channel_name[p], "output") && strcmp(data->channel_name[p], "input_value") && strcmp(data->channel_name[p], "output_value") + && strcmp(data->channel_name[p], "input_channel") && strcmp(data->channel_name[p], "interval")){ lua_getglobal(data->interpreter, data->channel_name[p]); data->reference[p] = luaL_ref(data->interpreter, LUA_REGISTRYINDEX); 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