02-17-2022, 11:06 PM
(02-17-2022, 04:21 PM)1e9t8m29 Wrote: I'm having trouble to understand what is dwmain. I run gcc -E with the following snippet and it prints nothing. It seems it can't interpret them.
Code:if defined(__WIN32__)
#define dwmain(a, b) \
_dwmain(a, b); \
char ** API _dw_convertargs(int *count, char *start, HINSTANCE hInstance); \
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {\
int argc; \
char **argv = _dw_convertargs(&argc, lpCmdLine, hInstance); \
return _dwmain(argc, argv); } \
int _dwmain(a, b)
"dwmain" is a macro that handles the entrypoint on various platforms.
On Windows the system entrypoint is WinMain() not main() ... so the "dwmain" macro on Windows will create a "WinMain() function that calls an internal library function _dw_convertargs() which changes the WinMain() arguments into the more standard main() style arguments. It then creates a _dwmain() function with the subsequent code which gets called from WinMain().
Most other platforms "dwmain" is just a macro that converts it to "main" (iOS and Android do additional processing to launch a message loop on the entrypoint thread... so the code in "dwmain" actually gets launched on a secondary thread).
But essentially "dwmain" is a macro that allows you to define a system entrypoint the same way regardless of what platform you are on.
Hope that makes sense?