WinMain, wWinMain, and win32 Character Set problems, winmainwwinmain

Source: Internet
Author: User

WinMain, wWinMain, and win32 Character Set problems, winmainwwinmain

When I first got started with win32 development, I found that the entry function in the default code of creating a win32 project with vs is not WinMain but _ tWinMain or wWinMain. What are the differences between these two functions?

WinMain corresponds to the multi-byte character set (ANSI) and wWinMain corresponds to the Unicode Character Set. _ TWinMain is defined in the tchar. h file:

# Ifdef _ UNICODE # define _ tWinMain wWinMain # else # define _ tWinMain WinMain # endif

 

When the character set is ANSI, it is equivalent to WinMain. When the character set is Unicode, it is equivalent to wWinMain.

To change the character set, click Project> Project Properties in.

 

Many functions of windows APIs are divided into two versions. For example, CreateWindow is defined as follows:

# Ifdef UNICODE # define CreateWindow CreateWindowW # else # define CreateWindow createwindowwa # endif

 

So when should we use the Unicode Character Set and the multi-byte character set?

In fact, the Unicode Character Set is not required when the program contains Chinese characters. When the windows system language is Chinese, no matter which character set you choose, the Chinese character set can be displayed normally, however, garbled characters may occur when the system language is not Chinese. So if your software needs to adapt to a multi-language windows system, you must use the Unicode Character Set.

In addition, when the character set is Unicode, a string passed to the api function should be converted to Unicode encoding. L conversion is available:

CreateWindow (wndClass, L "this is the title of the window ",......);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.