Sign in to follow this  
donjonson

I switched the character set to unicode and now I have some compile errors

Recommended Posts

I am using DXUT from the sdk samples. c++, DXUT requires the character set to be set to unicode but now everywhare i have a MessageBox() the 2nd arguement is just a string literal. it returns the error that it cant convert const char [x] to LPCWSTR. any ideas. I am going to try to just typecast it.

Share this post


Link to post
Share on other sites
Wrap your string literals with _T(). As in _T("I'm a string literal"). This will define the strings to be narrow when you build the app as a narrow character mode and wide when the app is build wide. Alternately you can just add the L prefix, but that changes the literal to be wide all the time.

Share this post


Link to post
Share on other sites
thank you very much, you have been very helpful. Whare can i go to learn more in depth about how all this works?

what is unicode? and how is it related to tchars and such?

So its probably a good idea to always use _T() with string literals then?

thanks

Share this post


Link to post
Share on other sites
One place to start is the Internationalization section on MSDN for how the Microsoft runtime handles narrow and wide character conversions. TCHAR is a MS convention. The TCHAR type is equal to a char normally and wchar_t when UNICODE is defined.

Unicode is a character set mapping that tries to get all the symbols used by all the languages in the world into the same mapping. That way a single data type can be used to represent, for example, English, German and Japanese all in the same program. However, you can't fit all that information in a normal char, which is usually 8 bits and so can only hold 256 numbers. The original version of unicode used 16 bits; the current version uses 21 bits.

Using the _T convention on your strings makes the code easier to port to a unicode version, but hurts portability in general since many compilers don't provide an equivalent to tchar.h.

Share this post


Link to post
Share on other sites
thanks for all the help, I have one more question. is ther a way to get the LPCWSTR out of the stringw class. is ther a member function like the the c_str() function only a c_strw() funcion hehe.

Share this post


Link to post
Share on other sites
Hmm that doesn't work. I am using the D3DXGetImageInfoFromFile() with the string.c_str()

it gives me the following error when it complies

'D3DXGetImageInfoFromFileW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'


any ideas?

Share this post


Link to post
Share on other sites
Take a look at my sample again. It's not a std::string it's a std::wstring, you need the w to specify that it stores wide characters.

Share this post


Link to post
Share on other sites
Quote:
Original post by donjonson
yeah i know but i think when unicode is selected, the compiler switches all of my string calls to wstring. but i might be wrong.

The compiler switches your Win32 calls to use wide characters. Functions like D3DXGetImageInfoFromFile() are actually #defined like this:


#ifdef UNICODE
#define D3DXGetImageInfoFromFile D3DXGetImageInfoFromFileW
#else
#define D3DXGetImageInfoFromFile D3DXGetImageInfoFromFileA
#endif



The STL does not work like this, however. You have to make sure to switch which version of string you are using.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this