November 4, 2004

wprintf/wcout has no UNICODE support

A couple of weeks ago I sent an Bug-Report via MSDN Product Feedback Center describing a bug which is present since the windows CRT is available. wprintf/wcout are not able to output UNICODE characters > 255 to the console.

Here is a small example which fails to output “A’Cyrillic letter EF’C”:

  #define UNICODE
  #define _UNICODE
  #include <tchar.h>
  #include <stdio.h>
  int _tmain()
  {
    _tprintf(_T("A\x0424") _T("C\n"));
    return 0;
  }

The problem is that it uses iternally a buffer. This buffer supports only multi-byte (MBCS). In the default locale (“C”) there is no conversion from UNICODE characters > 255 to an multi-byte string, there the output stops at the first UNICODE character > 255. Also the actual text is written via WriteFile to the console. But with WriteFile it is not possible to write UNICODE to the console. For this you must use WriteConsoleW

Also one problem is that MS is not able to provide the full UNICODE glyphs to the default console font! If you want to display UNICODE you must use WriteConsoleW and you must change the font to “Lucida Console”.

Martyn Lovell from MS posted on the bug, that there will be some kind of better support for UNICODE output in VS2005… but the current Beta has the same bug.

See also my older similar post


Posted 3 years, 3 months ago on November 4, 2004
The trackback url for this post is http://blog.kalmbachnet.de/bblog/trackback.php/23/

Comments have now been turned off for this post