From 709cf432f9af721ab64e799ee2f947f0da22c981 Mon Sep 17 00:00:00 2001 From: oxmox Date: Wed, 18 Dec 2024 19:00:58 +0100 Subject: [PATCH] implement spawn_doom() for windows --- src/doompanning.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/doompanning.cc b/src/doompanning.cc index 0ae3088..2304f9b 100644 --- a/src/doompanning.cc +++ b/src/doompanning.cc @@ -19,6 +19,7 @@ #include #ifdef __WIN32 +#include #else #include #include @@ -119,6 +120,37 @@ char **__environ = environ; #ifdef __WIN32 inline void spawn_doom(ControllerContext &ctx) { + (void) ctx; + + // Source: https://learn.microsoft.com/en-us/windows/win32/procthread/creating-processes + STARTUPINFO si; + PROCESS_INFORMATION pi; + + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + ZeroMemory(&pi, sizeof(pi)); + + char cmdLine[256]; + snprintf(cmdLine, sizeof(cmdLine), "%s", DOOM_EXECUTABLE); + + // Start the child process. + if (!CreateProcess(NULL, // No module name (use command line) + cmdLine, // Command line + NULL, // Process handle not inheritable + NULL, // Thread handle not inheritable + FALSE, // Set handle inheritance to FALSE + 0, // No creation flags + NULL, // Use parent's environment block + NULL, // Use parent's starting directory + &si, // Pointer to STARTUPINFO structure + &pi) // Pointer to PROCESS_INFORMATION structure + ) + { + log_error("CreateProcess failed (%d)", GetLastError()); + return; + } + + log_info("Spawned new %s, pid=%d", cmdLine, pi.dwProcessId); } #else void spawn_doom_posix_spawn(ControllerContext &ctx)