4 ms·
https://docs.microsoft.com/en-us/windows/win32/learnwin32/winmain--the-application-entry-point https://docs.microsoft.com/en-us/windows/win32/learnwin32/wi...
by sumtechguy 6y ago
https://docs.microsoft.com/en-us/windows/win32/learnwin32/winmain--the-application-entry-point https://docs.microsoft.com/en-us/windows/win32/learnwin32/wi...
You then pass it into https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw https://docs.microsoft.com/en-us/windows/win32/api/shellapi/... to get it split out if you need it.
I can see why they did it that way. No reason to waste cycles on something if you do not need it. Though most frameworks go and call it for you anyway these days.
- FreeFull 6y agoIt's a carryover from the MS-DOS days. One unfortunate part is that each program has to implement globs and any similar feature itself.
- frutiger 6y agoEven in a modern Unix, globs are expanded by the shell before invoking exec(3) with the individual arguments split out. They are not split/expanded by the C runtime.
- userbinator 6y ago...and I'm pretty sure DOS inherited it from CP/M.
- Someone 6y ago‘Implement’ isn’t necessary. That code could be provided by a shared library. That could be the superior option. Moving command line expansion into a shared library gets rid of the problem where the command line with globs expanded is too long, could have standardized option handling earlier (that system-provided library for globbing could easily grow to handle option flags), could better handle file names containing spaces, etc.
- ChrisSD 6y agoNote that WinMain isn't the "real" entry point either. The C runtime calls WinMain after doing its startup. By convention the entry point is one of: * mainCRTStartup * wmainCRTStartup * WinMainCRTStartup * wWinMainCRTStartup Conveniently these all have the exact same function signature (i.e. the real entry point signature). For example: extern "C" int WinMainCRTStartup() Although obviously the C runtime implementations differ for each of the listed entry points.
- sumtechguy 6y agohttps://docs.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol?view=vs-2019 https://docs.microsoft.com/en-us/cpp/build/reference/entry-e... You can also set what it is using that compiler option if you want. You usually do not want to as the default versions do quite a bit of stuff. I think the winmain one was the 3.x default. But changed when they added in other bits (I want to say threading, and console setup but I could be wrong). Windows is a weird one as it has this odd DOS/VMS/OS2/Win16/32 heritage so entry into the program is one that has some bagage. Winmain is one of those leftovers. The params passed in need to use the functions associated to them. My advice is always with this stuff. read the docs. There is a ton of info in there. It is kind of picky to get just right.
- ChrisSD 6y agoI'd also add that CommandLineToArgvW doesn't do exactly the same thing that the C runtime does to parse arguments. They used to be the same but the C runtime was tweaked in 2008 whereas CommandLineToArgvW was kept the same for backwards compatibility. See http://daviddeley.com/autohotkey/parameters/parameters.htm#WINCRULESREPH http://daviddeley.com/autohotkey/parameters/parameters.htm#W...
- Varriount 6y agoHuh. Wouldn't this have caused inter-operability problems for programs that spawn other processes?
- ChrisSD 6y agoPresumably they would have tested extensively for regressions. But I'm not sure what would break that wasn't already broken. It was an obscure undocumented case that was not intuitive.
- gpvos 6y agoOther links with code to parse/construct command lines: - https://web.archive.org/web/20200128073602/http://www.windowsinspired.com/how-a-windows-programs-splits-its-command-line-into-individual-arguments/ https://web.archive.org/web/20200128073602/http://www.window... - https://web.archive.org/web/20191119112915/https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ https://web.archive.org/web/20191119112915/https://blogs.msd...