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

Started by
13 comments, last by Colin Jeanne 18 years, 9 months ago
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.
These tears..leave scars...as they run down my face.
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.
What does narrow and wide mean?
These tears..leave scars...as they run down my face.
Narrow means normal chars. Wide means wchar_t.
do i need to source any libs for that to work? it doesn't seem to recognize _T()
These tears..leave scars...as they run down my face.
Try including tchar.h.
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
These tears..leave scars...as they run down my face.
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.
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.
These tears..leave scars...as they run down my face.
You should just be able to use the c_str() member function. ex:
  std::wstring wstr(L"Wide String");    LPCWSTR ptr = wstr.c_str();

This topic is closed to new replies.

Advertisement