Wednesday, April 20, 2011

How do you convert a Visual Studio project from using wide strings to ordinary strings.

When I created my visual studio project it defaulted to forcing me to use wide strings for all the functions which take character strings. MessageBox() for example, takes a LPCWSTR rather than a const char*. While I understand that it's great for multi-lingual and portable applications, it is completely unnecessary for my simple little app. Quite frankly, it's more of a pain to constantly type TEXT() around all my strings.

Is there a compiler option, define or project setting which I can alter to fix this in my Visual Studio project?

From stackoverflow
  • Right click on your project -> Properties then go to the following tree item:

    Configuration Properties -> General

    For Unicode select:
    Use Unicode Character Strings

    For normal multi-byte select:
    Use Multi-Byte Character Set

    When you put TEXT() or _T() around your strings, you are making it compatible with both of the character string options. If you select Use multi-byte character set then you do not need anything around your strings. If you select Use unicode character set, you need at least L in front of your strings.

    By selecting Use Unicode Character Strings you are also by default using all of the Win32 API that end in W. Example: MessageBox maps to MessageBoxW.

    When you select Use multi-byte character set you are also by default using all of the Win32 API that end in A. Example: MessageBox maps to MessageBoxA.

  • It is worth noting that you can explicitly declare wide character string literals of the form:

    WCHAR *s = L"Hello Wide World.";
    

    which requires fewer keystrokes than the macros TEXT() or _T(), but which will make a wide character string even if UNICODE is not defined.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.