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


On Aug  9 10:06, Corinna Vinschen wrote:
> On Aug  8 19:51, Charles Wilson wrote:
> > Anyway - Corinna, I dunno about Alexander/run but I'd like to see the
> > "incredibly simple" patch, for run2.
> 
> Well, the patch is dead simple, just look into my original mail.  Feel
> free to use it for run2 as well.

Argh.  It's not only simple, it's also wrong.  Having a second look into
the patch I see that I fetched the function pointers for AttachConsole
and GetConsoleWindow, but then used the real entry points, rather than
the pointers to call the functions.  Here's the corrected version:

--- 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-09 10:08:44.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 ();
+	  (*AttachConsoleFP) (child.dwProcessId);
+	  SetParent ((*GetConsoleWindowFP) (), HWND_MESSAGE);
+	}
       CloseHandle (child.hThread);
       CloseHandle (child.hProcess);
       if (bUsingPipes)


Corinna

-- 
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]