[Python-checkins] python/dist/src/PC WinMain.c,1.8,1.9

loewis at users.sourceforge.net loewis at users.sourceforge.net
Tue Sep 7 17:40:14 CEST 2004


Update of /cvsroot/python/python/dist/src/PC
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18738

Modified Files:
	WinMain.c 
Log Message:
Add support for launcher.exe

Index: WinMain.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/WinMain.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- WinMain.c	2 Aug 2002 02:27:12 -0000	1.8
+++ WinMain.c	7 Sep 2004 15:40:12 -0000	1.9
@@ -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 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);
 }



More information about the Python-checkins mailing list