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

Date:July 15, 2004 / year-entry #281
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20040715-00/?p=38433
Comments:    9
Summary: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...

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.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index