1

When developing a Win32 Application (non-console application) in Visual Studio 2005, is there any way to get the same sort of output as you do from the console?

For instance, say I want to see log statements (such as I would with cout in a console application) to trace the path my program has taken in the code.

My first thought would be that this could be done through the Output tab selecting something from its "Show output from:" dropdown, when debugging but I don't know what API I need to do this...

alt text

For example say I had the following in my windows application and wanted to know when the following function enters and exits writing the result to the Visual Studio window above.

void someFunction(void)
{
   Win32APIConsoleLog("BEGIN: someFunction()");
   // ...
   Win32APIConsoleLog("END: someFunction()");
}

Is this possible? And if so, what what libraries do I need to include and what function calls do I need to make to write out to the console window?

Community
  • 1
  • 1
leeand00
  • 25,510
  • 39
  • 140
  • 297
  • Just to clarify: You want to write to the console in Visual Studio, not the command prompt (separate console window with the black background), correct? – Adam Shiemke Jun 30 '10 at 13:21

1 Answers1

4

OutputDebugString.

I assume that you want to write to the debug console, since that's what your screenshot shows. OutputDebugString is a nop when no debugger is attached, but it allows you to log whatever you want to the debugger's output.

OutputDebugStringW(L"This will go to the output.\n");

// or

OutputDebugString("This will go to the output.\n");
Lam Le
  • 1,489
  • 3
  • 14
  • 31
JSBձոգչ
  • 40,684
  • 18
  • 101
  • 169
  • OutputDebugString is a normal API and it is not a NOP without a debugger, any usermode app can see the output (Sysinternals DebugView etc) – Anders Jun 30 '10 at 13:45
  • 1
    @Anders, true, but you have to ask for it specially. It's *not* the same as the console output, though the reader doesn't have to actually be a debugger. – JSBձոգչ Jun 30 '10 at 14:00
  • If no debugger (or debugview) is listening, the call is a NOP – Henrik Høyer Mar 08 '19 at 06:47