ref: 9a26795bd108ad33622abdb8431e100477a413f5
parent: 390a57c8d20a0b732b39aaa64bafdee749f17499
parent: bb6b315304f467a048097ad182e27030e402f859
author: Mike Swanson <[email protected]>
date: Tue Sep 10 16:52:38 EDT 2019
Merge pull request #1195 from AlexMax/master Use inherited handles to communicate with midiproc
--- a/midiproc/main.c
+++ b/midiproc/main.c
@@ -378,28 +378,12 @@
//
// Ensure that we can communicate.
//
-boolean InitPipes()
+void InitPipes(HANDLE in, HANDLE out)
{
- midi_process_in = GetStdHandle(STD_INPUT_HANDLE);
- if (midi_process_in == INVALID_HANDLE_VALUE)
- {
- goto fail;
- }
+ midi_process_in = in;
+ midi_process_out = out;
- midi_process_out = GetStdHandle(STD_OUTPUT_HANDLE);
- if (midi_process_out == INVALID_HANDLE_VALUE)
- {
- goto fail;
- }
-
atexit(FreePipes);
-
- return true;
-
-fail:
- FreePipes();
-
- return false;
}
//
@@ -410,7 +394,7 @@
int main(int argc, char *argv[])
{
// Make sure we're not launching this process by itself.
- if (argc < 3)
+ if (argc < 5)
{
MessageBox(NULL, TEXT("This program is tasked with playing Native ")
TEXT("MIDI music, and is intended to be launched by ")
@@ -446,10 +430,20 @@
snd_samplerate = 44100;
}
- if (!InitPipes())
+ // Parse out our handle ids.
+ HANDLE in = strtol(argv[3], NULL, 10);
+ if (in == 0)
{
return EXIT_FAILURE;
}
+
+ HANDLE out = strtol(argv[4], NULL, 10);
+ if (out == 0)
+ {
+ return EXIT_FAILURE;
+ }
+
+ InitPipes(in, out);
if (!InitSDL())
{
--- a/src/i_midipipe.c
+++ b/src/i_midipipe.c
@@ -414,7 +414,7 @@
DWORD dirname_len;
char *module = NULL;
char *cmdline = NULL;
- char snd_samplerate_buf[8];
+ char params_buf[128];
SECURITY_ATTRIBUTES sec_attrs;
PROCESS_INFORMATION proc_info;
STARTUPINFO startup_info;
@@ -439,13 +439,6 @@
// Define the module.
module = PROGRAM_PREFIX "midiproc.exe";
- // Define the command line. Version and Sample Rate follow the
- // executable name.
- M_snprintf(snd_samplerate_buf, sizeof(snd_samplerate_buf),
- "%d", snd_samplerate);
- cmdline = M_StringJoin(module, " \"" PACKAGE_STRING "\"", " ",
- snd_samplerate_buf, NULL);
-
// Set up pipes
memset(&sec_attrs, 0, sizeof(SECURITY_ATTRIBUTES));
sec_attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
@@ -476,13 +469,16 @@
return false;
}
+ // Define the command line. Version, Sample Rate, and handles follow
+ // the executable name.
+ M_snprintf(params_buf, sizeof(params_buf), "%d %Iu %Iu",
+ snd_samplerate, midi_process_in_reader, midi_process_out_writer);
+ cmdline = M_StringJoin(module, " \"" PACKAGE_STRING "\"", " ", params_buf, NULL);
+
// Launch the subprocess
memset(&proc_info, 0, sizeof(proc_info));
memset(&startup_info, 0, sizeof(startup_info));
startup_info.cb = sizeof(startup_info);
- startup_info.hStdInput = midi_process_in_reader;
- startup_info.hStdOutput = midi_process_out_writer;
- startup_info.dwFlags = STARTF_USESTDHANDLES;
ok = CreateProcess(TEXT(module), TEXT(cmdline), NULL, NULL, TRUE,
0, NULL, dirname, &startup_info, &proc_info);