mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-19 19:28:28 +00:00
Implement SDL_main as header-only lib for Win32
(remaining platforms will follow) SDL_main.h is *not* included by SDL.h anymore, users are supposed to include it directly now, usually only in the file they implement main() in. If they need the header elsewhere or don't want SDL_main to implement main() (but only call SDL_SetMainReady() or whatever), they can #define SDL_MAIN_HANDLED first, same as before. For SDL-internal usage, I added _SDL_MAIN_NOIMPL, which *also* skips the implementation and `#define main SDL_main`, but still defines SDL_MAIN_AVAILABLE and SDL_MAIN_NEEDED in SDL_main.h, as before. To make the implementaion in the header shorter and avoid including windows.h, I moved most of the Win32 SDL_main code into SDL3.dll via SDL_Win32RunApp(), so the header-only part is just the different main functions calling SDL_Win32RunApp(SDL_main, NULL) Note that I changed changed the return value and type of OutOfMemory() to return -1 instead of FALSE, so main() (or WinMain() or whatever) returns -1 instead of 0 in case of an out-of-memory error Compared to original Win32 SDL_main, I tweaked the part of the implementation in SDL_main_impl.h a bit to avoid linker warnings and conflicts with stuff from windows.h: - replaced windows.h with own define of WINAPI and typedef-ing HINSTANCE and LPSTR. This prevents conflicts between all the generically-named #defines and types in windows.h and user code (like DrawState in some SDL tests) - only using one of main() or wmain() gets rid of a MSVC linker error ("warning LNK4067: ambiguous entry point") If this still causes problems, we might try getting rid of wmain(), seemed to me like MSVC can use regular main() in UNICODE mode as well - simplified the UNICODE logic for that - while this is not exactly equivalent to the old, it should make sense and Works For Me
This commit is contained in:
parent
ffaf451558
commit
ca2fe7be1a
10 changed files with 214 additions and 105 deletions
|
@ -961,3 +961,6 @@ SDL_DYNAPI_PROC(Uint64,SDL_GetTicksNS,(void),(),return)
|
|||
SDL_DYNAPI_PROC(void,SDL_DelayNS,(Uint64 a),(a),)
|
||||
SDL_DYNAPI_PROC(Uint8,SDL_GetEventState,(Uint32 a),(a),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetRenderDriver,(int a),(a),return)
|
||||
#if defined(__WIN32__)
|
||||
SDL_DYNAPI_PROC(int,SDL_Win32RunApp,(SDL_main_func a, void *b),(a,b),return)
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue