Search code examples
cunicodewinapiwmain

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.


Solution

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