开发者

wmain vs main C runtime

开发者 https://www.devze.com 2023-01-12 16:31 出处:网络
I have read few articles about different Windows C entry pooints, wmain and WinMain. So, if I am correct, 开发者_开发知识库these are added to C language compilers for Windows OS. But, how are impleme

I have read few articles about different Windows C entry pooints, wmain and WinMain.

So, if I am correct, 开发者_开发知识库these are added to C language compilers for Windows OS. But, how are implemented?

For example, wmain gets Unicode as argv[], but its Os that sends these arguments to program, so is there any special field in the .exe file entry which says to windows to pass arguemnts as unicode? Thanks.


Modern versions of Windows internally use UTF-16. Therefore, when you launch an executable, all command line arguments likely are passed as UTF-16 from the onset, and the runtime library linked into the launched application either passes the arguments through unscathed (if using wmain) or converts them to the local encoding automatically (if using main). (Specifically this would be done by wmainCRTStartup/mainCRTStartup which are the actual entry points used for console Windows applications.)


First: a pedantic rant: wmain certainly does not get Unicode arguments. Unicode is defined independently of any particular encoding. wmain gets arguments in a 16 bit character encoding of Unicode, UTF-16 at a guess. I've just checked Microsoft's documentation on wmain and the links from it and it is clear that Microsoft had no clue about what Unicode is when they wrote it.

Anyway, the entry point of a program is defined by the linker. A C program always has a certain amount of prologue code that runs before main/wmain/WinMain/wWinMain. If one of the wide versions of main is used, the prologue code converts the characters in the environment from whatever character set they are in to the wide character version.

0

精彩评论

暂无评论...
验证码 换一张
取 消