16 out of 38 rated this helpful Rate this topic

OutputDebugString function

Sends a string to the debugger for display.

Syntax

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 Microsoft Windows Driver Kit (WDK) 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.

Visual Studio has changed how it handles the display of these strings throughout its revision history. Refer to the Visual Studio documentation for details of how your version deals with this.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

OutputDebugStringW (Unicode) and OutputDebugStringA (ANSI)

See also

Communicating with the Debugger
Debugging Functions

 

 

Send comments about this topic to Microsoft

Build date: 9/11/2011

Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ
Not Working?
I am running Windows 7 x86.

The OutputDebugString output in my program does not show in DebugView.
Windbg is not attached.

When i attached Windbg to the program, i am able to see the debug
statements in the debugger which is strange.

But Debugview would never show that same output when debugger is not
attached.

Already tried running DebugView at low integrity level as suggested
somewhere else on the internet. Did not work.

Any ideas?
C# syntax
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern void OutputDebugString(string message);

Debug.WriteLine() also calls this method internally.
Return Value
Actually, OutputDebugString returns a value in the EAX register which is related to whether the function succeeded or failed (whether a debugger is attached or not). I wasn't able to determine what does the "success" return value means (it looks like an address) because of the lack of documentation but I know the "failed" return value is 1.
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

C++ Wrapper Class
vb.net syntax
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Public Shared Sub OutputDebugString(ByVal message As String)
End Sub
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>


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).

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.
Truncating
Does Visual C++ truncating debugger string?  
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).