The solution was to close the pipe handles after creating the process.
So
if (!CreateProcess(
NULL,
filename, //TODO: check unicode?
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&si,
pi)
) {
printf("Could not create process\n");
return NULL;
}
CloseHandle(g_hChildStd_OUT_Wr);
CloseHandle(g_hChildStd_IN_Rd);
I guess because then only the child holds a handle to the resources, not the parent.