Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:

Want more? Here are some additional resources on this topic:

Visual Studio Automation and Extensibility Reference 
Debugger2 Interface 

The Debugger2 object is used to interrogate and manipulate the state of the debugger and the program being debugged. The Debugger2 object supersedes the Debugger object.

Namespace: EnvDTE80
Assembly: EnvDTE80 (in envdte80.dll)

Visual Basic (Declaration)
<GuidAttribute("8B5E2BFD-4642-4EFE-8AF4-0B2DA9AAA23C")> _
Public Interface Debugger2
	Inherits Debugger
Visual Basic (Usage)
Dim instance As Debugger2
C#
[GuidAttribute("8B5E2BFD-4642-4EFE-8AF4-0B2DA9AAA23C")] 
public interface Debugger2 : Debugger
C++
[GuidAttribute(L"8B5E2BFD-4642-4EFE-8AF4-0B2DA9AAA23C")] 
public interface class Debugger2 : Debugger
J#
/** @attribute GuidAttribute("8B5E2BFD-4642-4EFE-8AF4-0B2DA9AAA23C") */ 
public interface Debugger2 extends Debugger
JScript
GuidAttribute("8B5E2BFD-4642-4EFE-8AF4-0B2DA9AAA23C") 
public interface Debugger2 extends Debugger

The debugger is available through the DTE2 object via its Debugger property, as shown in the example below. One debugger object is available for each instance of the development environment.

Visual Basic
Imports EnvDTE
Imports System.Diagnostics

Public Module Module1
    'This function returns true if the debugger is actively debugging.

    Function IsDebugging() As Boolean
        Dim debugger As EnvDTE80.<b>Debugger2</b><b>debugger</b> = DTE2.Debugger

        If (<b>debugger</b> Is Nothing) Then
            MsgBox("Debugger doesn't exist! Fatal error.")
            IsDebugging = false
        Else
            IsDebugging = (<b>debugger</b>.CurrentMode <> _
            dbgDebugMode.dbgDesignMode)
        End If
    End Function
End Module
C++
// The following C++ program can be run from the command line.
// It detects whether an instance of Visual Studio is currently 
// running,and if so, prints a message stating whether its debugger
// is actively debugging.

#include <stdio.h>
#import "dte.olb" raw_interfaces_only named_guids
using namespace EnvDTE80;
int main(void)
{
    int nRet = 0;
    CoInitialize(NULL);
    IUnknownPtr pUnk;
    GetActiveObject(CLSID_DTE, NULL, &pUnk);
    if (pUnk == NULL) {
        printf ("No instance of Visual Studio is running.\n");
    }
    else {
        _DTEPtr pDTE = pUnk;
        if (pDTE) {
            DebuggerPtr pDebugger;
            if (SUCCEEDED(pDTE->get_Debugger(&<b>pDebugger2</b>)) && 
            <b>pDebugger2</b>
            != NULL){
                dbgDebugMode mode;
                if (SUCCEEDED(<b>pDebugger2</b>->get_CurrentMode(&mode))) {
                    if (mode != dbgDesignMode) {
                        printf("Debugger is active.\n");
                        nRet = 1;
                    }
                    else {
                        printf("Debugger is not active.\n");
                    }
                }
            }
        }
    }
    CoUninitialize();
    return nRet;
}
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker