Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is dwmain?
#2
(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?
Reply


Messages In This Thread
What is dwmain? - by 1e9t8m29 - 02-17-2022, 04:21 PM
RE: What is dwmain? - by dbsoft - 02-17-2022, 11:06 PM
RE: What is dwmain? - by 1e9t8m29 - 02-18-2022, 06:31 AM
RE: What is dwmain? - by dbsoft - 02-18-2022, 12:10 PM
RE: What is dwmain? - by 1e9t8m29 - 02-18-2022, 04:07 PM
RE: What is dwmain? - by dbsoft - 02-18-2022, 04:28 PM
RE: What is dwmain? - by dbsoft - 03-22-2022, 07:50 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)