0

I have a simple example to show the problem:

const wchar_t str[] = L"Hello-日本語-سلام-Ä-भारतीय-ไทย-";
OutputDebugStringW(str);

The result was as follow:

But when use MessageBox(NULL, str, L"", MB_OK);:

Why in the first case all languages did not appear correctly while in the second case all languages appear correctly?

Lion King
  • 32,851
  • 25
  • 81
  • 143
  • Maybe for `OutputDebugStringW` the debug monitor isn't sophisticated enough to figure out the encoding? – PaulMcKenzie Jun 24 '20 at 16:25
  • @PaulMcKenzie: The same result occurred when using the Visual Studio 2017 `output` window, so, what the problem then? – Lion King Jun 24 '20 at 16:29
  • Maybe you thought that handling non-ASCII text in any program is done "automatically" by the operating system -- that is not the case. If a program is written to not recognize the encoding, then you're stuck. The program will output gibberish, unless it was written to handle the encoding. – PaulMcKenzie Jun 24 '20 at 16:32
  • 1
    Does this answer your question? [Is there a Unicode alternative to OutputDebugString?](https://stackoverflow.com/questions/19442535/is-there-a-unicode-alternative-to-outputdebugstring) (PS: OutputDebugString is a pretty legacy stuff. You should use ETW, EventWriteString is similar, it just requires a call to EventRegister before using it, and you can gather traces it with a tool like this https://github.com/smourier/TraceSpy) – Simon Mourier Jun 24 '20 at 16:53
  • 1
    @SimonMourier - no, that answer was correct in 2013 but now `OutputDebugStringW` generate new exception `DBG_PRINTEXCEPTION_WIDE_C` - look for [example](https://ntquery.wordpress.com/2015/09/07/windows-10-new-anti-debug-outputdebugstringw/). problem not in this api, but in 2 things - are debugger understand `DBG_PRINTEXCEPTION_WIDE_C` ? if yes - all will be ok (i test in debugger which understand it and it correct print string). if no - problem because no correct conversion to `CP_ACP` - was lost information at this stage – RbMm Jun 24 '20 at 18:36
  • for example vs2019 correct display *Hello-日本語-سلام-Ä-भारतीय-ไทย-* string – RbMm Jun 24 '20 at 18:41
  • @RbMm - When you are not debugging (just reading DBWIN_DATA_READY events like DbgView like in OP's question or the TraceSpy tool I wrote), you'll still only get the ansi data. Plus it doesn't remove the fact it's a crappy,old,slow,limited,owner-free,unfilterable, etc. API IMHO. – Simon Mourier Jun 24 '20 at 19:55
  • @SimonMourier - yes, in case `DBWIN_BUFFER` used - only ansi string copied to section. but source of error - such unicode string can not be converted to `CP_ACP` ansi code page without lost information. how minimum for my ansi page )) – RbMm Jun 24 '20 at 23:50

0 Answers0