Code

add pdf import filter via poppler-cairo
[inkscape.git] / src / winmain.cpp
index dc6b7e00898cfcf5b48d76779c8dd2550b0ed474..752ab8e6bf6042cb61ad1c3f7cb23db9f6302aed 100644 (file)
@@ -6,8 +6,12 @@
 #include <glib.h>
 
 #ifdef G_OS_WIN32
-
 #undef DATADIR
+
+#include <stdio.h>
+#include <io.h>
+#include <conio.h>
+#define _WIN32_WINNT 0x0501
 #include <windows.h>
 
 extern int main (int argc, char **argv);
@@ -26,6 +30,28 @@ WinMain (struct HINSTANCE__ *hInstance,
         char               *lpszCmdLine,
         int                 nCmdShow)
 {
+    if (fileno (stdout) != -1 &&
+         _get_osfhandle (fileno (stdout)) != -1)
+       {
+         /* stdout is fine, presumably redirected to a file or pipe */
+       }
+    else
+    {
+         typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
+
+         AttachConsole_t p_AttachConsole =
+           (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
+
+         if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
+      {
+             freopen ("CONOUT$", "w", stdout);
+             dup2 (fileno (stdout), 1);
+             freopen ("CONOUT$", "w", stderr);
+             dup2 (fileno (stderr), 2);
+
+      }
+       }
+
        int ret;
        ret = main (__argc, __argv);
        return ret;