Debugging Windows C++ programs | Joachim De Zutter
Using a format string to output debug messages with relevant program variables to OutputDebugStringA:
#include <windows.h>
#include <stdarg.h>
void DbgPrintf(const char *fmt, ...)
{
	va_list params;
	char szBuf[512];
	va_start(params, fmt);
	vsprintf_s(szBuf, 512, fmt, params);
	va_end(params);
	OutputDebugStringA(szBuf);
}
In Visual Studio we may see the debug messages in the Output window (ALT+2).
With Windows Sysinternals DebugView we can filter/highlight the debug messages received by calling DbgPrintf based on specific parts of the debug output to narrow down the root cause(s) of the bug.