summaryrefslogtreecommitdiffstats
path: root/PC/WinMain.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2004-09-07 15:40:12 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2004-09-07 15:40:12 (GMT)
commit97329754f8651c21d32dc6032227b7981faa6066 (patch)
tree52562b7c9440da19c495523acde15ad335949432 /PC/WinMain.c
parent4b2017ae1ad347651586467055c3019c4a40b6df (diff)
downloadcpython-97329754f8651c21d32dc6032227b7981faa6066.zip
cpython-97329754f8651c21d32dc6032227b7981faa6066.tar.gz
cpython-97329754f8651c21d32dc6032227b7981faa6066.tar.bz2
Add support for launcher.exe
Diffstat (limited to 'PC/WinMain.c')
-rw-r--r--PC/WinMain.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/PC/WinMain.c b/PC/WinMain.c
index 00dc18d..58305d1 100644
--- a/PC/WinMain.c
+++ b/PC/WinMain.c
@@ -2,9 +2,25 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#include <fcntl.h>
#include "Python.h"
+#ifdef LAUNCHER
+/* Q105305 suggests this routine to adjust the handles. */
+static void adjust_file(DWORD handle, FILE* f, char* mode)
+{
+ int hCrt;
+ FILE *hf;
+ hCrt = _open_osfhandle((intptr_t)GetStdHandle(handle), _O_TEXT);
+ hf = _fdopen(hCrt, mode);
+ *f = *hf;
+ setvbuf(f, NULL, _IONBF, 0);
+ /* Alternatively, we could use __set_app_type and _set_osfhnd,
+ but that appears to be undocumented. */
+}
+#endif
+
int WINAPI WinMain(
HINSTANCE hInstance, /* handle to current instance */
HINSTANCE hPrevInstance, /* handle to previous instance */
@@ -12,5 +28,19 @@ int WINAPI WinMain(
int nCmdShow /* show state of window */
)
{
+#ifdef LAUNCHER
+ int i;
+ if (__argc > 1 && strcmp(__argv[1], "-console") == 0) {
+ /* Allocate a console, and remove the -console argument. */
+ AllocConsole();
+ for (i = 2; i < __argc; i++)
+ __argv[i-1] = __argv[i];
+ __argc--;
+ /* Make stdin, stdout, stderr use the newly allocated OS handles. */
+ adjust_file(STD_INPUT_HANDLE, stdin, "r");
+ adjust_file(STD_OUTPUT_HANDLE, stdout, "w");
+ adjust_file(STD_ERROR_HANDLE, stderr, "w");
+ }
+#endif
return Py_Main(__argc, __argv);
}