aboutsummaryrefslogtreecommitdiffhomepage
path: root/midimonster.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2020-02-29 15:35:08 +0100
committercbdev <cb@cbcdn.com>2020-02-29 15:35:08 +0100
commit9c564af18dc3faad8910bfe14b45ed4ab884d797 (patch)
treede6811a3439930cd0b9e19aa87558b3a2f7a4025 /midimonster.c
parent454e757f740b74d714e9fa47bfa4954cb30e67ba (diff)
downloadmidimonster-9c564af18dc3faad8910bfe14b45ed4ab884d797.tar.gz
midimonster-9c564af18dc3faad8910bfe14b45ed4ab884d797.tar.bz2
midimonster-9c564af18dc3faad8910bfe14b45ed4ab884d797.zip
Keep console alive when exiting as last process on Windows
Diffstat (limited to 'midimonster.c')
-rw-r--r--midimonster.c21
1 files changed, 18 insertions, 3 deletions
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;
}