Don’t forget to #define UNICODE if you want Unicode


I answered this comment directly, but it deserves reiteration with wider visibility.

If you don’t #define UNICODE, you get ANSI by default.

If you want to see characters beyond the boring 7-bit ASCII, make sure you are using a font that can display those characters.

I am assuming a level of competence where issues like this go without saying, so that I can dig into the more advanced topics without having to explain all the basics, but I have to accept that people of all levels of programming experience read my stuff.

But the second part raises an advanced question: How do you find a font that can display the characters you want? What if the characters can come from a source outside your control? We’ll look at this tomorrow.

Comments (9)
  1. Gene Hamilton says:

    Also what about "#define _UNICODE"?

  2. Skywing says:

    _UNICODE is for the C runtime’s TCHAR support, i.e. _tcscpy (–> wcscpy vs strcpy). This is distinct from UNICODE, which turns, say, CreateWindowEx into CreateWindowExW instead of CreateWindowExA.

  3. Jack Mathews says:

    If one were to say just call the W versions of functions and structures explicitly, would there be a real reason to define UNICODE ?

    Just curious, even though typing W all the time is a pain, it could allow a project to have a steady migration over to unicode.

    Jack

  4. Raymond Chen says:

    Yes you can switch over gradually by manually inserting W’s and L’s on a per-call basis.

  5. Matt says:

    Where does Microsoft document this?

    It seems like the first rule of _UNICODE is that you don’t talk about _UNICODE. If you don’t know about it in the first place, it’s awfully hard to figure it all out from Microsoft’s documentation.

  6. Raymond Chen says:

    ??? If it’s a secret it’s a really badly kept one. #1 hit for _UNICODE on MSDN is http://msdn.microsoft.com/library/en-us/vccore/html/_core_generic.2d.text_mappings_in_tchar..h.asp

  7. Centaur says:

    That’s the way from “I know there is a conditional named _UNICODE” to “I know what _UNICODE does”. Though, the inverse is also easy; the page about strcpy mentions both _UNICODE and _MBCS.

  8. Ankur Goel says:

    Use Arial Unicode for all your font needs :)

Comments are closed.