OutputDebugString Function

Sends a string to the debugger for display.

Syntax

C++
void WINAPI OutputDebugString(
  __in_opt  LPCTSTR lpOutputString
);

Parameters

lpOutputString [in, optional]

The null-terminated string to be displayed.

Return Value

This function does not return a value.

Remarks

If the application has no debugger, the system debugger displays the string if the filter mask allows it. (Note that this function calls the DbgPrint function to display the string. For details on how the filter mask controls what the system debugger displays, see the DbgPrint function in the Windows Driver Kit on MSDN.) If the application has no debugger and the system debugger is not active, OutputDebugString does nothing.

Prior to Windows Vista:  The system debugger does not filter content.

OutputDebugStringW converts the specified string based on the current system locale information and passes it to OutputDebugStringA to be displayed. As a result, some Unicode characters may not be displayed correctly.

Applications should send very minimal debug output and provide a way for the user to enable or disable its use. To provide more detailed tracing, see Event Tracing.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesOutputDebugStringW (Unicode) and OutputDebugStringA (ANSI)

See Also

Communicating with the Debugger
Debugging Functions

Send comments about this topic to Microsoft

Build date: 7/30/2009

Tags :


Community Content

Sandu Buraga
What's the 64-bit Variant?

OutputDebugString() doesn't seem to work on Vista 64-bit .

Is there a variant for Vista x64 that works similar to the Win32 OutputDebugString()?

I want to use the DebugView 4.64 to capture debug output on Vista x64 .

 

OK. GOT IT.!!

This is the SOLUTION:

In DebugView 4.64 , make sure that Capture Global Win32 is enabled. To do this, in the DebugView 4.64 main menu go to Capture and see if the Capture Global Win32 item is checked. If not, check it.

Upon doing this, you'll notice that OutputDebugString() output appears in DebugView 4.64 on Vista x64 . :)

The same problem is on Windows 2003 SP1 and R2 and it can be fixed in the same manner, this comment would be useful also for the .net developers (see System.Diagnostics Debug and Trace classes).


Jacky Kim
WinDbg does not receive OutputDebugString from Vista

I connected Vista as Debuggee to WinDbg(6.6.7.5) bya 1394 and serial.

Connection was successful, But WinDbg does not display OutputDebugString from Debug Mode Vista.

It worked well on Windows XP. What is difference from XP Debug Mode and Visa Debug Mode?

[Answer]

In Vista, certain registry setting is required for Debug String Output.

HKLM\SYSTEM\CCS\Control\Session Manager\Debug Print Filter

Refer to below.

http://www.osronline.com/article.cfm?article=295

Tags : contentbug

Jakub Nietrzeba
Truncating
Does Visual C++ truncating debugger string?  
Tags : contentbug

Dwayne Robinson
Kernel mode debug messages
Note that to send a string while in kernel mode (device driver level), you should use DbgPrint/KdPrint. DbgPrintEx also supports message filtering based on the component IDs and severity level.
Tags :

Austin Donnelly MSFT
Implementation details

For implementation details, see also:

http://www.unixwiz.net/techtips/outputdebugstring.html

Brief summary: one global mutex serialising access, a 4KB shared memory buffer for the string, and a couple of events to signal who "owns" the buffer (reader or writer).

Tags :

Charlweed
The output goes to the "Immediate Window"
Once you know, you know,
But we wasted hours on this.

In Visual Studio 2008, the output of this function goes to the "Immediate Window", not the Output window. The immediate window is closed by default, so it seems like the output is lost.

Also, if you find "Winbase.h (include Windows.h)" confusing, the correct include directive for a c++ native application is

#include <windows.h>


Tags :

dmex
vb.net syntax
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Public Shared Sub OutputDebugString(ByVal message As String)
End Sub
Tags : vb.net syntax

dmex
C# syntax
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern void OutputDebugString(string message);
Tags : c# syntax

Page view tracker