0

I use:

OutputDebugString(L"My error");

in Visual Studio 2010, but instead of displaying "My error", I get just an "ERROR" in the window.

enter image description here

How do I fix this issue?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
YAKOVM
  • 9,805
  • 31
  • 116
  • 217

1 Answers1

5

Since you're explicitly passing an UNICODE string, I'd suggest you also explicitly call OutputDebugStringW().

Otherwise, if the UNICODE preprocessor symbol is not defined in your compilation unit, the ANSI version of the function (OutputDebugStringA()) would end up being called with an UNICODE string, which it does not support, and it should result in a compilation error.

EDIT: You cannot use OutputDebugString() to write a string in your application's status bar. OutputDebugString() only sends the string you pass to the debugger.

You have to use the appropriate API to write text to the status bar instead. In your case, wxStatusBar::SetStatusText() should do the trick.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • 4
    You *should* get a compiler error if you pass a Unicode string to a function that is expecting an ANSI string. – Cody Gray - on strike Jul 23 '11 at 13:21
  • @Cody, indeed, normally the compiler *should* be able to tell `char *` from `wchar_t *`, but it's C++, so implicit conversion constructors and cast operators *can* mess with that, I suppose. Answer updated, thank you for your comment :) – Frédéric Hamidi Jul 23 '11 at 13:23
  • It still doesn`t work!I checked that UNICODE preprocessor symbol is defined and I call OutputDebugStringW (this is done by macro,where OutputDebugString is defined as OutputDebugStringW if UNICODE is defined : #ifdef UNICODE #define OutputDebugString OutputDebugStringW #else #define OutputDebugString OutputDebugStringA #endif // !UNICODE – YAKOVM Jul 23 '11 at 13:58
  • @Yakov, does your program compile at all? If it does, can you tell us exactly where you're looking for the `My error` message? – Frédéric Hamidi Jul 23 '11 at 14:01
  • 2
    @Frédéric Hamidi I display it in the status bar.Before OutputDebugStringW run it is written OK there.After the run it changes to ERROR,instead of "My error" – YAKOVM Jul 23 '11 at 14:14
  • @Yakov, did you write code to capture `OutputDebugString()`'s output and send it to the status bar? `OutputDebugString()` only talks to the debugger by default. – Frédéric Hamidi Jul 23 '11 at 14:18
  • @ Frédéric Hamidi - probably no.I use object of my class which derives from wxGLCanvas to display the message.From this object I call some error reporting function that I wrote.The only thing this function does - run OutputDebugString with the argument as described above. – YAKOVM Jul 23 '11 at 14:30