[AD] END_OF_MAIN removal patch for msvc |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hello, people. There was a discussion about removing END_OF_MAIN this
summer, see http://tinyurl.com/5jd23y (mailing list archive). Here's a
patch and some thoughts about this, please comment. :)
I've had some trouble building allegro 5 on msvc, but now I've got it
working. So I've attached a patch which makes END_OF_MAIN just an empty
macro on msvc.
I've added ALLEGRO_ALLOW_WINMAIN as a way to let users use WinMain
without having to override the /entry switch themselves.
Some questions remain:
1) This means that apps built with allegro 5 on msvc will by default
have a console window. But this is what happens on other Windows
compilers already, at least mingw does this. So how to disable the
console will definitely become a FAQ for msvc users. Adding the
required linker option to allegro headers is an option. See below.
#ifdef ALLEGRO_USE_CONSOLE
#pragma comment(linker,"/SUBSYSTEM:windows").
#endif
Not sure I like this, though. Seems a bit over the top, or what?
2) This opens up the possibility to remove ALLEGRO_USE_CONSOLE and
ALLEGRO_CONSOLE_OK. They're only useful on Windows. Other platforms
always define ALLEGRO_CONSOLE_OK, and ignore ALLEGRO_USE_CONSOLE.
ALLEGRO_CONSOLE_OK has dubious value, as the console can be disabled or
enabled by flipping a switch in the exe header after the app is already
built. A runtime check could probably be added, if there's a real need
for it.
3) OS X and QNX uses END_OF_MAIN to get hold of the address of
_mangled_main. A different solution needed? And is
ALLEGRO_WITH_MAGIC_MAIN needed? It's off by default.
4) Most of the examples and tools that come with allegro need to be
built without a console window by setting something in the build config,
since END_OF_MAIN no longer takes care of this. CMake's ADD_EXECUTABLE
function has a WIN32 flag that seems to be the right way to do this.
Maybe the 'example' macro in allegro's build system could get a similar
flag? I'll leave that to someone who knows the build system.
Index: include/allegro5/platform/alwin.h
===================================================================
--- include/allegro5/platform/alwin.h (revision 11221)
+++ include/allegro5/platform/alwin.h (working copy)
@@ -24,44 +24,7 @@
#include <windows.h>
#endif
-/*******************************************/
-/********** magic main emulation ***********/
-/*******************************************/
-#ifdef __cplusplus
-extern "C" {
-#endif
-AL_FUNC(int, _WinMain, (void *_main, void *hInst, void *hPrev, char *Cmd, int nShow));
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#if (!defined ALLEGRO_NO_MAGIC_MAIN) && (!defined ALLEGRO_SRC)
-
- #define ALLEGRO_MAGIC_MAIN
- #define main _mangled_main
- #undef END_OF_MAIN
-
- /* disable strict pointer typing because of the vague prototype below */
- #define NO_STRICT
-
- #ifdef __cplusplus
- extern "C" int __stdcall WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *Cmd, int nShow);
- #endif
-
- #define END_OF_MAIN() \
- \
- int __stdcall WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *Cmd, int nShow) \
- { \
- return _WinMain((void *)_mangled_main, hInst, hPrev, Cmd, nShow); \
- }
-
-#endif
-
-
-
/*******************************************/
/************* system drivers **************/
/*******************************************/
Index: include/allegro5/platform/almsvc.h
===================================================================
--- include/allegro5/platform/almsvc.h (revision 11221)
+++ include/allegro5/platform/almsvc.h (working copy)
@@ -46,8 +46,9 @@
#define ALLEGRO_NO_MAGIC_MAIN
#endif
-#ifdef ALLEGRO_AND_MFC
- #define ALLEGRO_NO_MAGIC_MAIN
+/* stop msvc linker complaining about missing WinMain */
+#if (!defined ALLEGRO_ALLOW_WINMAIN) && (!defined ALLEGRO_LIB_BUILD)
+ #pragma comment(linker,"/ENTRY:mainCRTStartup")
#endif