Win32 Application Console Output

consoledebuggingtracevisual-studio-2005winapi

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?

Best Answer

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");