Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
outputdebugstring (kernel32)
 
.
Summary

Sends a string to the debugger for display.

C# Signature:

[DllImport("kernel32.dll")]
static extern void OutputDebugString(string lpOutputString);

VB.NET Signature:

<DllImport("kernel32.dll")> _
Shared Sub OutputDebugString(ByVal lpOutputString As String)
End Sub

Or (as in VB 6)

Public Declare Sub OutputDebugString Lib "kernel32" Alias _
    "OutputDebugStringA" (ByVal lpOutputString As String)

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Get DebugView here (http://www.sysinternals.com/Utilities/DebugView.html) to display the output of OutputDebugString.

This C# example extends the OutputDebugString(...) with variable arguments:

        public static void OutputDebugStringVarArg(
        string format,
        params object[] args)
        {
        try
        {
            OutputDebugString(string.Format(format, args));
        }
        catch (Exception)
        {
            return;
        }
        }

Now run the function as follows: OutputDebugStringVarArg("It is {0} past {1}", new object[] {5,10 });

Get OutputDebugString function implementation that accepts variable number of arguments like printf here (http://www.go4expert.com/forums/showthread.php?t=871)

Sample Code:

1. Create a new C# windows console application project.

2. Add the following

using System.Runtime.InteropServices;

below

using System.Text;

3. Add the following as the first statement of the main function.

OutputDebugString("OutputDebugString Successfully executed");

Now execute the program with DebugView Open

Alternative Managed API:

System.Diagnostics.Debug.WriteLine

System.Diagnostics.Debugger.Log

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions