Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is dwmain?
#4
(02-18-2022, 06:31 AM)1e9t8m29 Wrote: If _dwmain is declared like this: int _dwmain(a, b) then where is the definition of it? It can't be the int WINAPI WinMain because this very function return _dwmain(argc, argv).
Please give me the preprocessed (by hand) of that snippet, I want to know what you actually wanted to write in plain C code, without macros. Thanks.

Ok the way these type of preprocessor macros work is they replace anything starting with "dwmain(" and ending with ")" ... the a and b will be filled in with whatever is in those positions. 

So an entrypoint defintiion like this:

Code:
int dwmain(int argc, char **argv)
{
  return 0;
}

would result in the following code being generated:

Code:
int _dwmain(int argc, char **argv);
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(int argc, char **argv)
{
  return 0;
}

The _dwmain definition starts with "int" because that was before the "dwmain(" macro.

So this one definition creates 2 functions.... the WinMain() function, which is the actual application entrypoint and a _dwmain() internal function which contains your code.

The WinMain() function does the work of converting the arguments and then calls the internal function containing your code.

Make more sense now?

Brian
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)