Call TerminateProcess on Unreal game created from CreateProcess
I have two distinct applications: An Unreal packaged game (I will call it “game”) and another Windows application (wich I will call “app”) that creates the game with CreateProcess and tries to kill it with TerminateProcess, both from Windows SDK (processthreadsapi.h).
I call CreateProcess in the app with the code:
void CreateUnrealServerProcess()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
bool processCreated = CreateProcess(
NULL,
const_cast<char*>(fullExecutablePath.c_str()),
NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi
) != 0;
serverProcessHandle = pi.hProcess;
}
And after the game is loaded and running, I’m trying to kill it with:
bool processTerminated = TerminateProcess(serverProcessHandle, 0);
But the game window don’t get closed, and the process keeps alive.
My game uses ObjectDeliverer, configured to act as a TCP server, and has just a first person shooter template with a landscape.
The return from TerminateProcess is no error.
Any hints on what is happening? I know I could send a message to the game with TCP to finish it from Unreal, but now I need to kill it from the process that created the game.