1

Using OutputDebugString is a common debugging technique for user mode debugging.

In UWP/UAP/Metro app developement on Windows 10, this debugging function is still available.

However, I would like to observe OutputDebugString messages without attaching Visual Studio debugger (EDIT: or WinDbg).

Latest version of DbgViewer from SysInternals is able to observe UWP debug output, but I can't find the source code for this tool.

Actually, DebugViewPP from CobaltFusion appears to work for win32 apps only.

As a workaround, I could simply use LogginChannel.LogMessage but I'm currently more interested by how OutputDebugString API work under UWP.

LostAPI
  • 11
  • 2
  • Use windbg https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools And have a read of https://learn.microsoft.com/en-gb/windows-hardware/drivers/devtest/reading-and-filtering-debugging-messages – Richard Critten Nov 09 '19 at 13:49
  • Thanks for your message, however, it doesn't help to know how ::OutputDebugString API is implemented under UWP. Also, WinDbg is too heavy for my purpose. – LostAPI Nov 09 '19 at 14:07
  • In the page you linked for `OutputDebugString`: _"...Note that this function calls the DbgPrint function to display the string..."_ Then follow my second link to receiving / processing these messages. – Richard Critten Nov 09 '19 at 14:16
  • A debugger receives the string when it calls WaitForDebugEventEx(), OUTPUT_DEBUG_STRING_EVENT notification. SysInternals' hack is to patch the OS kernel to get this for any process, not just the one that a debugger attached. Using this yourself is not very practical, you'll lose the ability to debug your program the normal way. – Hans Passant Nov 09 '19 at 17:49
  • Is there a way to launch a UWP app from WinDbgX, the preview version ? – LostAPI Nov 09 '19 at 17:53
  • Thanks a lot Hans, the good old way https://blogs.msdn.microsoft.com/reiley/2011/07/29/a-debugging-approach-to-outputdebugstring/ doesn't seem to be relevant for UWP app. – LostAPI Nov 09 '19 at 17:55

1 Answers1

-2

OutputDebugString function exists in Kernel32.dll file, if you want to use it in UWP, you can import the dll file by DllImport.

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void OutputDebugString(string message);
private async void Button_Click(object sender, RoutedEventArgs e)
{
    OutputDebugString("~~~OutputDebugString");
}
Faywang - MSFT
  • 5,798
  • 1
  • 5
  • 8