Call TerminateProcess on Unreal game created from CreateProcess

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()

  ZeroMemory(&si, sizeof(si));
  si.cb = sizeof(si);
  ZeroMemory(&pi, sizeof(pi));

  bool processCreated = CreateProcess(
    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.

Not a complete answer, but this only occurs when packaging in development mode (which makes me think the game may be running as subprocess, without job object assignment).

::TerminateProcess does work as intended on executables packaged in shipping mode however.

Related note: neither WM_CLOSE nor WM_QUIT messages work however.