remote-viewer: make it a GUI/windows application with hybrid console

If the application can attach to its parent console, redirect
input/output. So that will work nicely with the command line wrapper.
This commit is contained in:
Marc-André Lureau 2012-04-02 19:54:21 +02:00
parent 55477f9f20
commit db1b308a63
2 changed files with 16 additions and 0 deletions

View File

@ -87,6 +87,7 @@ remote_viewer_SOURCES = \
remote-viewer-main.c \
$(NULL)
remote_viewer_LDFLAGS = \
-Wl,--subsystem,windows \
$(GLIB2_LIBS) \
$(GTK_LIBS) \
$(LIBXML2_LIBS) \

View File

@ -25,6 +25,10 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <stdlib.h>
#ifdef G_OS_WIN32
#include <windows.h>
#include <io.h>
#endif
#ifdef HAVE_GTK_VNC
#include <vncdisplay.h>
@ -222,6 +226,17 @@ main(int argc, char **argv)
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
#ifdef G_OS_WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONERR$", "w", stderr);
dup2(fileno(stdin), STDIN_FILENO);
dup2(fileno(stdout), STDOUT_FILENO);
dup2(fileno(stderr), STDERR_FILENO);
}
#endif
#if !GLIB_CHECK_VERSION(2,31,0)
g_thread_init(NULL);
#endif