使用 Window 应用程序显示 OutputDebugString 消息?

Showing OutputDebugString messages with Window application?

我正在开发 Windows 应用程序,并希望在 window 处于 运行ning 时使用 OutputDebugString 函数将调试消息输出到控制台。

问题是我不知道如何实现。 如果我 运行 window 来自 Visual studio 的应用程序,则不会显示任何控制台,因为它是链接器设置中的 windows/subsystem:windows

如果我 运行 来自控制台的 window 程序,命令行会在显示 window.

后半途终止

我如何才能同时显示 CMD 和 window 以查看传递给 OutputDebugString 函数的调试消息?

使用 sysinternals 中的 DebugView 来捕获和显示这些调试消息:

Under Windows 2000, XP, Server 2003 and Vista DebugView will capture:

Win32 OutputDebugString
Kernel-mode DbgPrint
All kernel-mode variants of DbgPrint implemented in Windows XP and Server 2003 DebugView also extracts kernel-mode debug output generated before a crash from Window's 2000/XP crash dump files if DebugView was capturing at the time of the crash.