views:

47

answers:

2

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?

A: 

Maybe this article can help you.

renick
+4  A: 

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.

JSBangs
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
@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.
JSBangs
@Anders What is NOP?
leeand00
@leeand00 http://en.wikipedia.org/wiki/NOP
Anders