IDTCommandTarget.Exec Method
Visual Studio 2005
Executes the specified named command.
Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)
Assembly: EnvDTE (in envdte.dll)
void Exec ( [InAttribute] string CmdName, [InAttribute] vsCommandExecOption ExecuteOption, [InAttribute] ref Object VariantIn, [InAttribute] out Object VariantOut, [InAttribute] out bool Handled )
void Exec ( /** @attribute InAttribute() */ String CmdName, /** @attribute InAttribute() */ vsCommandExecOption ExecuteOption, /** @attribute InAttribute() */ /** @ref */ Object VariantIn, /** @attribute InAttribute() */ /** @attribute OutAttribute() */ /** @ref */ Object VariantOut, /** @attribute InAttribute() */ /** @attribute OutAttribute() */ /** @ref */ boolean Handled )
JScript does not support passing value-type arguments by reference.
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 that it was not.
The following example uses the Command object and its AddNamedCommand and AddControl methods, and the IDTCommandTarget interface and its (Exec and QueryStatus) methods, to demonstrate how to make an Add-in appear as a command on the Tools menu in Visual Studio. 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