This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New run version with patches for Windows 7


I've attached the important parts of the patch that I've used to
generate run-1.1.11.  I've actually combined both of the two approaches:

1) for cygwin-1.7, use
   http://cygwin.com/ml/cygwin-apps/2009-08/msg00022.html

2) for (cygwin-1.5 || mingw) && WinXP or above, use
   http://cygwin.com/ml/cygwin-apps/2009-08/msg00016.html

3) implicitly, for (cygwin-1.5 || mingw) && Win2k or below, use
   original setup_invisible_console() stuff

Seems to work as expected under all combinations of
(cygwin-1.7/cygwin-1.5/mingw) x (WinXP/Vista). I didn't explicitly test
W7...

Packages should be on the mirrors soon. I'd appreciate reports concerning
   cygwin-1.5 + run-1.1.11-1  + Windows7
   cygwin-1.7 + run-1.1.11-10 + Windows7

--
Chuck
diff --git a/src/run.c b/src/run.c
index ba2e536..171f5d7 100644
--- a/src/run.c
+++ b/src/run.c
@@ -27,9 +27,16 @@
  * console window lying around. Ditto for desktop shortcuts to gnu-win32 
  * X11 executables.
  */
+#if HAVE_CONFIG_H
+#  include "config.h"
+#endif
 
-
+#ifndef WIN32
 #define WIN32
+#endif
+
+/* pull in WinXP function declarations, especially AttachConsole */
+#define _WIN32_WINNT 0x0501
 
 #include <windows.h>
 #include <winuser.h>
@@ -53,7 +60,7 @@ WinMainCRTStartup() { mainCRTStartup(); }
  #include <direct.h>
 #endif
 
-
+DWORD os_version;
 char buffer[1024];
 
 int WINAPI
@@ -71,6 +78,8 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow)
    int i,j;
    char exec[MAX_PATH + FILENAME_MAX + 100];
    char cmdline2[MAX_ARGS * MAX_PATH];
+   DWORD vers = GetVersion ();
+   os_version = (LOBYTE (LOWORD (vers)) << 8) | HIBYTE (LOWORD (vers));
 
    cmdline = GetCommandLine();
    /* strip program name. Maybe quoted? */
@@ -343,14 +352,38 @@ int start_child(char* cmdline, int wait_for_child)
    BOOL bUsingPipes;
    HANDLE hToChild, hFromChild;
    HANDLE hToParent, hFromParent;
+   BOOL WINAPI (*AttachConsoleFP)(DWORD) = NULL;
+   HWND WINAPI (*GetConsoleWindowFP)(VOID) = NULL;
 
    setup_win_environ();
 
+#if (defined (__CYGWIN__) && !HAVE_DECL_CYGWIN_CONV_PATH) || defined(__MINGW32__)
+   /* mingw or cygwin-1.5: work around bug in Windows 7, but also
+    * employ on XP and above. This means that setup_invisible_console()
+    * is now used only on <= Win2k */
+   if (os_version >= 0x0501)
+     {
+       HMODULE lib = GetModuleHandle ("kernel32.dll");
+       AttachConsoleFP = (BOOL WINAPI (*)(DWORD))
+           GetProcAddress (lib, "AttachConsole");
+       GetConsoleWindowFP = (HWND WINAPI (*)(VOID))
+           GetProcAddress (lib, "GetConsoleWindow");
+       if (!AttachConsoleFP || !GetConsoleWindowFP)
+           os_version = 0;
+     }
+#endif
+
 #ifdef DEBUG_FORCE_PIPES
    bHaveInvisConsole = FALSE;
    FreeConsole();
+#elif defined (__CYGWIN__) && HAVE_DECL_CYGWIN_CONV_PATH
+   /* cygwin-1.7 */
+   bHaveInvisConsole = TRUE;
 #else
-   bHaveInvisConsole = setup_invisible_console();
+   /* mingw or cygwin-1.5: work around bug in Windows 7, but also
+    * employ on XP and above. This means that setup_invisible_console()
+    * is now used only on <= Win2k */
+   bHaveInvisConsole = os_version >= 0x0501 ? TRUE : setup_invisible_console();
 #endif
 
    if (!configure_startupinfo(&start, bHaveInvisConsole,
@@ -370,7 +403,11 @@ int start_child(char* cmdline, int wait_for_child)
        NULL,    /* process security attributes         */
        NULL,    /* primary thread security attributes  */
        TRUE,    /* handles are inherited,              */
+#if defined(__CYGWIN__) && HAVE_DECL_CYGWIN_CONV_PATH
+       CREATE_NO_WINDOW,
+#else
        0,       /* creation flags                      */
+#endif
        NULL,    /* use parent's environment            */
        NULL,    /* use parent's current directory      */
        &start,  /* STARTUPINFO pointer                 */
@@ -411,6 +448,17 @@ int start_child(char* cmdline, int wait_for_child)
           }
           GetExitCodeProcess (child.hProcess, &retval);
       } 
+#if (defined(__CYGWIN__) && !HAVE_DECL_CYGWIN_CONV_PATH) || defined(__MINGW32__)
+     /* mingw or cygwin-1.5: work around bug in Windows 7, but also
+      * employ on XP and above. This means that setup_invisible_console()
+      * is now used only on <= Win2k */
+      if (os_version >= 0x0501)
+      {
+        FreeConsole ();
+        (*AttachConsoleFP) (child.dwProcessId);
+        SetParent ((*GetConsoleWindowFP) (), HWND_MESSAGE);
+      }
+#endif
       CloseHandle (child.hThread);
       CloseHandle (child.hProcess);
       if (bUsingPipes)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]