简体   繁体   中英

Character Sets in VS2010

I am using VS2010 and I have these in my code:

::MessageBox(0, "Init FAILED", 0, 0);

When I compiled the project, I got the error that cannot convert parameter 2 from 'const char [25]' to 'LPCWSTR'. I searched the problem on the Internet, people told me to change the 'character sets' option in my project settings from 'Unicode' to 'Not Set'. But it does not work. When I run these codes:

#ifdef UNICODE
    printf("unicode");
#else
    printf("others");
#endif

I get the same answer "unicode" no matter what option I have chosen. What should I do to handle the problem?

To answer your original question, you didn't need to change the character set. The solution is to use the _T() macro that is defined in tchar.h.

::MessageBox(0, _T("Init Failed"), 0, 0);

The _T() macro will either specify a wide string by appending an "L" onto the string, or an ANSI string by leaving the string alone.

You should change the character set only if you truly want to use the character set you're changing to. You don't change the character set just because your code doesn't compile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM