Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wmain vs main C runtime

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.

like image 637
B.Gen.Jack.O.Neill Avatar asked Nov 15 '25 08:11

B.Gen.Jack.O.Neill


1 Answers

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

like image 102
jamesdlin Avatar answered Nov 18 '25 00:11

jamesdlin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!