2 * "$Id: fl_call_main.c 7903 2010-11-28 21:06:39Z matt $"
4 * Copyright 1998-2010 by Bill Spitzak and others.
6 * fl_call_main() calls main() for you Windows people. Needs to be done in C
7 * because Borland C++ won't let you call main() from C++.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * Please report all bugs and problems on the following page:
26 * http://www.fltk.org/str.php
30 * This WinMain() function can be overridden by an application and
31 * is provided for compatibility with programs written for other
32 * operating systems that conform to the ANSI standard entry point
33 * "main()". This will allow you to build a WIN32 Application
34 * without any special settings.
36 * Because of problems with the Microsoft Visual C++ header files
37 * and/or compiler, you cannot have a WinMain function in a DLL.
38 * I don't know why. Thus, this nifty feature is only available
39 * if you link to the static library.
41 * Currently the debug version of this library will create a
42 * console window for your application so you can put printf()
43 * statements for debugging or informational purposes. Ultimately
44 * we want to update this to always use the parent's console,
45 * but at present we have not identified a function or API in
46 * Microsoft(r) Windows(r) that allows for it.
49 #if defined(WIN32) && !defined(FL_DLL) && !defined (__GNUC__)
54 # include <FL/fl_utf8.h>
56 extern int main(int, char *[]);
61 # endif /* BORLAND5 */
63 /* static int mbcs2utf(const char *s, int l, char *dst, unsigned dstlen) */
64 static int mbcs2utf(const char *s
, int l
, char *dst
)
70 mbwbuf
= (xchar
*)malloc(dstlen
* sizeof(xchar
));
71 l
= mbstowcs(mbwbuf
, s
, l
);
72 /* l = fl_unicode2utf(mbwbuf, l, dst); */
73 l
= fl_utf8fromwc(dst
, dstlen
, mbwbuf
, l
);
79 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
80 LPSTR lpCmdLine
, int nCmdShow
) {
86 * If we are using compiling in debug mode, open a console window so
87 * we can see any printf's, etc...
89 * While we can detect if the program was run from the command-line -
90 * look at the CMDLINE environment variable, it will be "WIN" for
91 * programs started from the GUI - the shell seems to run all WIN32
92 * applications in the background anyways...
96 freopen("conin$", "r", stdin
);
97 freopen("conout$", "w", stdout
);
98 freopen("conout$", "w", stderr
);
101 ar
= (char**) malloc(sizeof(char*) * (__argc
+ 1));
107 for (l
= 0; __wargv
[i
] && __wargv
[i
][l
]; l
++) {}; /* is this just wstrlen??? */
108 dstlen
= (l
* 5) + 1;
109 ar
[i
] = (char*) malloc(dstlen
);
110 /* ar[i][fl_unicode2utf(__wargv[i], l, ar[i])] = 0; */
111 dstlen
= fl_utf8fromwc(ar
[i
], dstlen
, __wargv
[i
], l
);
114 for (l
= 0; __argv
[i
] && __argv
[i
][l
]; l
++) {};
115 dstlen
= (l
* 5) + 1;
116 ar
[i
] = (char*) malloc(dstlen
);
117 /* ar[i][mbcs2utf(__argv[i], l, ar[i], dstlen)] = 0; */
118 ar
[i
][mbcs2utf(__argv
[i
], l
, ar
[i
])] = 0;
123 /* Run the standard main entry point function... */
124 rc
= main(__argc
, ar
);
135 #elif defined(__hpux)
136 /* This code to prevent "empty translation unit" or similar warnings... */
137 static void dummy(void) {}
138 #endif /* WIN32 && !FL_DLL && !__GNUC__ */
141 * End of "$Id: fl_call_main.c 7903 2010-11-28 21:06:39Z matt $".