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 <stdio.h>
12 #include <io.h>
13 #include <conio.h>
14 #define _WIN32_WINNT 0x0501
15 #include <windows.h>
17 extern int main (int argc, char **argv);
19 /* In case we build this as a windowed application */
21 #ifdef __GNUC__
22 # ifndef _stdcall
23 # define _stdcall __attribute__((stdcall))
24 # endif
25 #endif
27 int _stdcall
28 WinMain (struct HINSTANCE__ *hInstance,
29 struct HINSTANCE__ *hPrevInstance,
30 char *lpszCmdLine,
31 int nCmdShow)
32 {
33 if (fileno (stdout) != -1 &&
34 _get_osfhandle (fileno (stdout)) != -1)
35 {
36 /* stdout is fine, presumably redirected to a file or pipe */
37 }
38 else
39 {
40 typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
42 AttachConsole_t p_AttachConsole =
43 (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
45 if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
46 {
47 freopen ("CONOUT$", "w", stdout);
48 dup2 (fileno (stdout), 1);
49 freopen ("CONOUT$", "w", stderr);
50 dup2 (fileno (stderr), 2);
52 }
53 }
55 int ret;
56 ret = main (__argc, __argv);
57 return ret;
58 }
60 #endif