Skip to main content
gamedev.net
🔒 Locked

Unicode with VS2008/C++

Started by essial Jan 16, 2008 at 10:38 PM 1 replies 6.2k views
Original Post
essial
essial
I am working on an application using visual studio 2008 and c++. I am very familiar with C++, and generally familiar with the visual studio 2kx series IDEs, but I have not done anything with unicode and that setup before. What precautions, setup, and code considerations (aside from the obvious of using WCHAR instead of char) must I use to make my application support unicode? Is there any project options that must be changed or is unicode support defaulted in? Thanks!
gan
gan
Quote:
I am very familiar with C++, and generally familiar with the visual studio 2kx series IDEs, but I have not done anything with unicode and that setup before.

check your MSDN, it comes with example, at: ms-help://MS.MSDNQTR.v90.en/dv_vcsampxpr/html/f34a0cf9-fb26-4a7d-b4b0-dfbef48bb52d.htm

Quote:
Addtional note from MSDN:
You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.


Quote:
Is there any project options that must be changed or is unicode support defaulted in?

Right-click your VC++ project
Under "Configuration Properties">General>"Character Set">"Use Unicode Character Set"

??
MJP
MJP
In VS 2005 and above, Unicode is the default setting for new projects. There are a few considerations you'll need to take when working with Unicode:

-When using string literals, make sure they're Unicode string literals. You can do this by placing an 'L' before the string like this:
WCHAR str [] = L"This is a Unicode string!";


-This is obvious, but don't treat WCHAR's as CHAR's. They no longer have a size of one byte, and you can't send them to any function looking for CHAR* or LPSTR.

-If you want to use std::string, use std::wstring. It's the same string class for Unicode. There's also wide character versions of ifstream and ofstream, named wifstream and wofstream respectively.

-Be aware of how TCHAR works: it's typedef'ed to evaluate to either CHAR or WCHAR depending on your project's Unicode settings. It can be used to create programs that will compiler with Unicode on or off. TCHAR string literals can be created with the TEXT() macro.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.