Hello
I have made a COM Add-in in Visual Studio .NET 2003 by using a standard
shared Add-in project. The Add-in is for MS Project, and I have managed to
add a menu point to the MSP menu. However I can not catch the click event
for the commandBarControl!
I can not cast the application object I have in the OnConnection sub from
the type System.__COMObject to the type EnvDTE.DTE using CType; I get an
InvalidCastException. My code can be seen in the bottom of this mail.
What am I doing wrong? Why does the OnConnection sub not have an application
object of type EnvDTE.DTE which I can use to catch the click event?
Troels Grosbøll-Poulsen
--
Imports Microsoft.Office.Core
Imports EnvDTE
Imports Extensibility
Imports System.Runtime.InteropServices
<GuidAttribute("C7E1314D-89FA-48C5-B48C-1B6BD6D68172"),
ProgIdAttribute("MSProjectIntegration.Connect")> _
Public Class Connect
Implements IDTExtensibility2
Dim applicationObject As EnvDTE.DTE
<System.ContextStatic()> Public WithEvents commandBarEvents As
EnvDTE.CommandBarEvents
....
Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array)
Implements IDTExtensibility2.OnConnection
....
Try
applicationObject = CType(application, EnvDTE.DTE)
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString())
End Try
....
End Sub
....
End Class
|