Code

4fde2c5748ade9eefa3483a669e237c9f26ecea6
[inkscape.git] / src / winmain.cpp
1 #ifdef HAVE_CONFIG_H
2 # include "config.h"
3 #endif
5 #include <stdlib.h>
6 #include <glib.h>
8 #ifdef G_OS_WIN32
9 #undef DATADIR
11 #include <io.h>
12 #include <conio.h>
13 #define _WIN32_WINNT 0x0501
14 #include <windows.h>
16 extern int main (int argc, char **argv);
18 /* In case we build this as a windowed application */
20 #ifdef __GNUC__
21 #  ifndef _stdcall
22 #    define _stdcall  __attribute__((stdcall))
23 #  endif
24 #endif
26 int _stdcall
27 WinMain (struct HINSTANCE__ *hInstance,
28          struct HINSTANCE__ *hPrevInstance,
29          char               *lpszCmdLine,
30          int                 nCmdShow)
31 {
32     if (fileno (stdout) != -1 &&
33           _get_osfhandle (fileno (stdout)) != -1)
34         {
35           /* stdout is fine, presumably redirected to a file or pipe */
36         }
37     else
38     {
39           typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
41           AttachConsole_t p_AttachConsole =
42             (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
44           if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
45       {
46               freopen ("CONOUT$", "w", stdout);
47               dup2 (fileno (stdout), 1);
48               freopen ("CONOUT$", "w", stderr);
49               dup2 (fileno (stderr), 2);
51       }
52         }
54         int ret;
55         ret = main (__argc, __argv);
56         return ret;
57 }
59 #endif