This documentation is archived and is not being maintained.

Exec Method

Visual Studio .NET 2003

Executes the specified named command.

[Visual Basic .NET]
Public Sub Exec( _
   ByVal CmdName As String, _
   ByVal ExecuteOption As vsCommandExecOption, _
   ByVal VariantIn As Variant, _
   VariantOut As Variant, _
   handled As Boolean _
) 
[Visual Basic 6]
Sub Exec( _
   ByVal CmdName As String, _
   ByVal ExecuteOption As vsCommandExecOption, _
   ByVal VariantIn As Variant, _
   VariantOut As Variant, _
   handled As Boolean _
) 
[C++]
HRESULT __stdcall Exec(
   BSTR CmdName,
   vsCommandExecOption ExecuteOption,
   VARIANT* VariantIn,
   VARIANT* VariantOut,
   VARIANT_BOOL* handled
);
[C#]
void Exec(
   string CmdName,
   vsCommandExecOption ExecuteOption,
   ref object VariantIn,
   ref object VariantOut,
   ref bool handled
);
[JScript .NET]
public function Exec(
   CmdName : String,
   ExecuteOption : vsCommandExecOption,
   VariantIn : Object,
   VariantOut : Object,
   handled : Boolean
)

Parameters

CmdName
The name of the command to execute.
ExecuteOption
A vsCommandExecOption constant specifying the execution options.
VariantIn
A value passed to the command.
VariantOut
A value passed back to the invoker Exec method after the command executes.
handled
True indicates that the command was implemented. False indicates it was not.

Example

The following example uses both the Command object and its AddNamedCommand and AddControl methods, and the IDTCommandTarget interface and its two methods (Exec and QueryStatus) to demonstrate how to make an Add-in appear as a command on the Tools menu in Visual Studio .NET. Note that this code does not work in a macro.

Implements IDTCommandTarget

Dim applicationObject As EnvDTE.DTE
Dim addInInstance as EnvDTE.AddIn
   
Dim objAddIn As AddIn = CType(addInInst, AddIn)
Dim CommandObj As Command
Try
   CommandObj = applicationObject.Commands.AddNamedCommand(objAddIn, "MyAddin1", "MyAddin1", "Executes the command for MyAddin1", True, 59, Nothing, 1 + 2)
   '1+2 == vsCommandStatusSupported+vsCommandStatusEnabled
   CommandObj.AddControl(applicationObject.CommandBars.Item("Tools"))
Catch e as System.Exception
End Try

Public Sub Exec(ByVal cmdName As String, ByVal executeOption As vsCommandExecOption, ByRef varIn As Object, ByRef varOut As Object, ByRef handled As Boolean) Implements IDTCommandTarget.Exec
   handled = False
   If (executeOption = vsCommandExecOption.vsCommandExecOptionDoDefault) Then
      If cmdName = "MyAddin1.Connect.MyAddin1" Then
         handled = True
         Exit Sub
      End If
   End If
End Sub
   
Public Sub QueryStatus(ByVal cmdName As String, ByVal neededText As vsCommandStatusTextWanted, ByRef statusOption As vsCommandStatus, ByRef commandText As Object) Implements IDTCommandTarget.QueryStatus
   If neededText = EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone Then
      If cmdName = "MyAddin1.Connect.MyAddin1" Then
         statusOption = CType(vsCommandStatus.vsCommandStatusEnabled & vsCommandStatus.vsCommandStatusSupported, vsCommandStatus)
      Else
         statusOption = vsCommandStatus.vsCommandStatusUnsupported
      End If
   End If
End Sub  

See Also

Applies To: IDTCommandTarget Interface

Show: