4

OutputDebugString() is native ASCII, which means it convert the input Unicode string to local string before call the ASCII version OutputDebugStringA().

Is there any alternative to OutputDebugString() which supports Unicode?

sharptooth
  • 167,383
  • 100
  • 513
  • 979
Jichao
  • 40,341
  • 47
  • 125
  • 198

1 Answers1

5

OutputDebugStringW does internally call OutputDebugStringA, so Unicode characters that cannot be represented in the system code page will be replaced with ?.

Oddly enough, the OUTPUT_DEBUG_STRING_INFO structure the debugger receives from the operating system to print the message does appear to support letting the debugger know if the string is Unicode, it just doesn't appear to be used by OutputDebugStringW at all.

Unfortunately, I don't know of a mechanism to get the OS to raise a OUTPUT_DEBUG_STRING_EVENT with a Unicode string. It may not be possible with public APIs.

Peter Huene
  • 5,758
  • 2
  • 34
  • 35
  • 5
    The [documentation](https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-outputdebugstringw) says: "*Important: **In the past, the operating system did not output Unicode strings via `OutputDebugStringW` and instead only output ASCII strings**. To force `OutputDebugStringW` to correctly output Unicode strings, debuggers are required to call `WaitForDebugEventEx` to opt into the new behavior. On calling `WaitForDebugEventEx`, the operating system will know that the debugger supports Unicode and is specifically opting into receiving Unicode strings*" Use an up-to-date debugger – Remy Lebeau Jun 24 '20 at 18:00