fre0n
fre0n

Reputation: 1915

Redirect stdout to Visual Studio output window from native c++ dll

I have a c# windows app that calls a managed c++ dll, which, in turn, calls a native c++ dll. There seem to be some performance issues in the native c++ code, so I'm doing some simple profiling. I'd like to dump the results of the profiling so that the Visual Studio output window picks it up. I thought that printf would do the trick, but nothing shows up in either the Output window or the Immediate window. I also tried fprintf, but that doesn't work either.

Upvotes: 3

Views: 3460

Answers (1)

Daryl Hanson
Daryl Hanson

Reputation: 458

Try OutputDebugString

OutputDebugString is rather plain, so I tend to add the following to my projects to make it function like printf (making sure to avoid overrunning the buffer size):

#if (_VERBOSE)
void DebugPrintf (LPTSTR lpFormat, ...)
{
    TCHAR szBuf[1024];
    va_list marker;

    va_start( marker, lpFormat );
    _vstprintf( szBuf, lpFormat, marker );
    OutputDebugString( szBuf );
    va_end( marker );
}
#endif

Upvotes: 7

Related Questions