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]

New run version with patches for Windows 7


Hi Alexander,

are you still with us in some way?  There hasn't been a new version of
the "run" tool for ages.  Now, with the upcoming Windows 7,  it's
necessary to workaround a bug in W7 in terms of creating an invisible
console.  I have experimented a lot and came up with an incredible
simple patch based on an idea from cgf.  I restricted the code to os
versions >= Windows 7, but it works fine on Windows XP and later if the
os_version checks are changed from checking for >= 0x0601 to checking for
>= 0x0501.  XP is the minimum version providing the AttachConsole function.

Would you mind to create a new run package with this patch?


Thanks in advance,
Corinna


--- run-1.1.10.orig/src/run.c	2006-05-22 14:32:43.000000000 +0200
+++ run-1.1.10/src/run.c	2009-08-08 23:48:17.000000000 +0200
@@ -30,7 +30,7 @@
 
 
 #define WIN32
-
+#define _WIN32_WINNT 0x0601
 #include <windows.h>
 #include <winuser.h>
 #include <string.h>
@@ -53,6 +53,7 @@ WinMainCRTStartup() { mainCRTStartup();
  #include <direct.h>
 #endif
 
+DWORD os_version;
 
 char buffer[1024];
 
@@ -72,6 +73,8 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPre
    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? */
    if (*cmdline == '\"')
@@ -346,11 +349,24 @@ int start_child(char* cmdline, int wait_
 
    setup_win_environ();
 
+   BOOL WINAPI (*AttachConsoleFP)(DWORD) = NULL;
+   HWND WINAPI (*GetConsoleWindowFP)(VOID) = NULL;
+   if (os_version >= 0x0601)
+     {
+       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;
+     }
+
 #ifdef DEBUG_FORCE_PIPES
    bHaveInvisConsole = FALSE;
    FreeConsole();
 #else
-   bHaveInvisConsole = setup_invisible_console();
+   bHaveInvisConsole = os_version >= 0x0601 ? TRUE : setup_invisible_console();
 #endif
 
    if (!configure_startupinfo(&start, bHaveInvisConsole,
@@ -411,6 +427,12 @@ int start_child(char* cmdline, int wait_
           }
           GetExitCodeProcess (child.hProcess, &retval);
       } 
+      if (os_version >= 0x0601)
+      	{
+	  FreeConsole ();
+	  AttachConsole (child.dwProcessId);
+	  SetParent (GetConsoleWindow (), HWND_MESSAGE);
+	}
       CloseHandle (child.hThread);
       CloseHandle (child.hProcess);
       if (bUsingPipes)

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat


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