Jump to content
  • Advertisement
Sign in to follow this  
donjonson

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

This topic is 4731 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
You should just be able to use the c_str() member function. ex:

std::wstring wstr(L"Wide String");

LPCWSTR ptr = wstr.c_str();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!