Skip to content

Commit 9732975

Browse files
committed
Add support for launcher.exe
1 parent 4b2017a commit 9732975

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎PC/WinMain.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,45 @@
22

33
#define WIN32_LEAN_AND_MEAN
44
#include <windows.h>
5+
#include <fcntl.h>
56

67
#include "Python.h"
78

9+
#ifdef LAUNCHER
10+
/* Q105305 suggests this routine to adjust the handles. */
11+
static void adjust_file(DWORD handle, FILE* f, char* mode)
12+
{
13+
int hCrt;
14+
FILE *hf;
15+
hCrt = _open_osfhandle((intptr_t)GetStdHandle(handle), _O_TEXT);
16+
hf = _fdopen(hCrt, mode);
17+
*f = *hf;
18+
setvbuf(f, NULL, _IONBF, 0);
19+
/* Alternatively, we could use __set_app_type and _set_osfhnd,
20+
but that appears to be undocumented. */
21+
}
22+
#endif
23+
824
int WINAPI WinMain(
925
HINSTANCE hInstance, /* handle to current instance */
1026
HINSTANCE hPrevInstance, /* handle to previous instance */
1127
LPSTR lpCmdLine, /* pointer to command line */
1228
int nCmdShow /* show state of window */
1329
)
1430
{
31+
#ifdef LAUNCHER
32+
int i;
33+
if (__argc > 1 && strcmp(__argv[1], "-console") == 0) {
34+
/* Allocate a console, and remove the -console argument. */
35+
AllocConsole();
36+
for (i = 2; i < __argc; i++)
37+
__argv[i-1] = __argv[i];
38+
__argc--;
39+
/* Make stdin, stdout, stderr use the newly allocated OS handles. */
40+
adjust_file(STD_INPUT_HANDLE, stdin, "r");
41+
adjust_file(STD_OUTPUT_HANDLE, stdout, "w");
42+
adjust_file(STD_ERROR_HANDLE, stderr, "w");
43+
}
44+
#endif
1545
return Py_Main(__argc, __argv);
1646
}

0 commit comments

Comments
 (0)