addin is ClassLibrary type and I need to have form shown also.
the problem is this
_applicationObject is set back to nothing after user click button on the form
The question is how to work with forms (that will be used to enter soem data)
and then call back method in connnect.vb module to execute it ?
Imports System Imports Microsoft.VisualStudio.CommandBars Imports Extensibility Imports EnvDTE Imports EnvDTE80 Public Class Connect Implements IDTExtensibility2, IDTCommandTarget, IWin32Window Private _applicationObject As DTE2 Private _addInInstance As AddIn '''<summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary> Public Sub New() End Sub '''<summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> '''<param name='application'>Root object of the host application.</param> '''<param name='connectMode'>Describes how the Add-in is being loaded.</param> '''<param name='addInInst'>Object representing this Add-in.</param> '''<remarks></remarks> Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection _applicationObject = CType(application, DTE2) _addInInstance = CType(addInInst, AddIn) If connectMode = ext_ConnectMode.ext_cm_UISetup Then Dim commands As Commands2 = CType(_applicationObject.Commands, Commands2) Dim toolsMenuName As String = "Tools" 'Place the command on the tools menu. 'Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: Dim commandBars As CommandBars = CType(_applicationObject.CommandBars, CommandBars) Dim menuBarCommandBar As CommandBar = commandBars.Item("MenuBar") 'Find the Tools command bar on the MenuBar command bar: Dim toolsControl As CommandBarControl = menuBarCommandBar.Controls.Item(toolsMenuName) Dim toolsPopup As CommandBarPopup = CType(toolsControl, CommandBarPopup) Try 'Add a command to the Commands collection: Dim command As Command = commands.AddNamedCommand2(_addInInstance, "MyAddin4", "MyAddin4", "Executes the command for MyAddin4", True, 59, Nothing, CType(vsCommandStatus.vsCommandStatusSupported, Integer) + CType(vsCommandStatus.vsCommandStatusEnabled, Integer), vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton) 'Find the appropriate command bar on the MenuBar command bar: command.AddControl(toolsPopup.CommandBar, 1) Catch argumentException As System.ArgumentException 'If we are here, then the exception is probably because a command with that name ' already exists. If so there is no need to recreate the command and we can ' safely ignore the exception. End Try End If End Sub '''<summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary> '''<param name='disconnectMode'>Describes how the Add-in is being unloaded.</param> '''<param name='custom'>Array of parameters that are host application specific.</param> '''<remarks></remarks> Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) Implements IDTExtensibility2.OnDisconnection End Sub '''<summary>Implements the OnAddInsUpdate method of the IDTExtensibility2 interface. Receives notification that the collection of Add-ins has changed.</summary> '''<param name='custom'>Array of parameters that are host application specific.</param> '''<remarks></remarks> Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate End Sub '''<summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary> '''<param name='custom'>Array of parameters that are host application specific.</param> '''<remarks></remarks> Public Sub OnStartupComplete(ByRef custom As Array) Implements IDTExtensibility2.OnStartupComplete InitializeAddIn() End Sub '''<summary>Implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being unloaded.</summary> '''<param name='custom'>Array of parameters that are host application specific.</param> '''<remarks></remarks> Public Sub OnBeginShutdown(ByRef custom As Array) Implements IDTExtensibility2.OnBeginShutdown End Sub '''<summary>Implements the QueryStatus method of the IDTCommandTarget interface. This is called when the command's availability is updated</summary> '''<param name='commandName'>The name of the command to determine state for.</param> '''<param name='neededText'>Text that is needed for the command.</param> '''<param name='status'>The state of the command in the user interface.</param> '''<param name='commandText'>Text requested by the neededText parameter.</param> '''<remarks></remarks> Public Sub QueryStatus(ByVal commandName As String, ByVal neededText As vsCommandStatusTextWanted, ByRef status As vsCommandStatus, ByRef commandText As Object) Implements IDTCommandTarget.QueryStatus If neededText = vsCommandStatusTextWanted.vsCommandStatusTextWantedNone Then If commandName = "MyAddin4.Connect.MyAddin4" Then status = CType(vsCommandStatus.vsCommandStatusEnabled + vsCommandStatus.vsCommandStatusSupported, vsCommandStatus) Else status = vsCommandStatus.vsCommandStatusUnsupported End If End If End Sub '''<summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary> '''<param name='commandName'>The name of the command to execute.</param> '''<param name='executeOption'>Describes how the command should be run.</param> '''<param name='varIn'>Parameters passed from the caller to the command handler.</param> '''<param name='varOut'>Parameters passed from the command handler to the caller.</param> '''<param name='handled'>Informs the caller if the command was handled or not.</param> '''<remarks></remarks> Public Sub Exec(ByVal commandName 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 commandName = "MyAddin4.Connect.MyAddin4" Then handled = True InitializeAddIn() Exit Sub End If End If End Sub Public Sub test() Dim sol As Solution = _applicationObject.Solution End Sub Private Sub InitializeAddIn() Dim frm1 As Form1 frm1 = New Form1() frm1.ShowInTaskbar = True frm1.StartPosition = FormStartPosition.CenterParent frm1.ShowDialog(Me) End Sub Public ReadOnly Property Handle As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle Get ' Wraps the Win32 handle of the Visual Studio main window Return New IntPtr(_applicationObject.MainWindow.HWnd) End Get End Property End Class