L
ljavis
OnConnection runs fine. I stepped through line by line and there are no
exceptions of any sort. I followed the example from "Outlook Com Add-in
for VB.NET" by microeye which I downloaded from the link in the
Microsoft's article. OnDisconnection does not happen and I also noticed
that the add in does not appear in the Tools|Options|...|COM Add-Ins...
The add-in works as far as it's been implemented with the side effect
of Outlook remaining in memory after UI is gone because add-in never
disconnects. Any ideas? This is rather urgent.
Connect looks like this:
Imports Microsoft.Office.Core
imports Extensibility
imports System.Runtime.InteropServices
#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such
as:
' 1) You moved this project to a computer other than which is was
originally created on.
' 2) You chose 'Yes' when presented with a message asking if you wish
to remove the Add-in.
' 3) Registry corruption.
' you will need to re-register the Add-in by building the
reflexionOLSetup project
' by right clicking the project in the Solution Explorer, then choosing
install.
#End Region
<GuidAttribute("CE862D54-3B61-4A79-942E-ABADE3AFDCAF"),
ProgIdAttribute("reflexionOL.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Private OutAddInObj As OutAddIn = New OutAddIn
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
Dim oApp As Outlook.Application
Dim oType As Type
Dim GetProgID As Object
Dim MyProgID As String
Dim oArgs As Object()
Try
'Use InvokeMember to get ProgID of addInInst object
oType = addInInst.GetType
GetProgID = oType.InvokeMember("ProgID", _
Reflection.BindingFlags.Public Or
Reflection.BindingFlags.Public Or Reflection.BindingFlags.GetField Or
Reflection.BindingFlags.GetProperty, _
Nothing, _
addInInst, _
oArgs)
MyProgID = CType(GetProgID, String)
'Convert application from generic object to
Outlook.Application
oApp = CType(application, Outlook.Application)
'Don't call InitHandler if Explorers.Count = 0 and
Inspectors.Count = 0
If oApp.Explorers.Count = 0 And oApp.Inspectors.Count = 0
Then
Exit Sub
End If
'Evaluate ConnectMode
Select Case connectMode
Case ext_ConnectMode.ext_cm_AfterStartup
Case ext_ConnectMode.ext_cm_CommandLine
Case ext_ConnectMode.ext_cm_External
Case ext_ConnectMode.ext_cm_Solution
Case ext_ConnectMode.ext_cm_Startup
Case ext_ConnectMode.ext_cm_UISetup
End Select
' Initialize COMAddin object with this connect object to
allow
' external clients to get access to exposed features
oApp.COMAddIns.Item(MyProgID.ToString).Object = Me
'Call InitHandler
Me.OutAddInobj.InitHandler(oApp, MyProgID)
Catch ex As SystemException
'DebugWriter("OnConnection Exception: {0}", ex.Message)
End Try
End Sub
Private Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
Dim oCommandBars As Office.CommandBars
Dim oStandardBar As Office.CommandBar
Dim oCBB As CommandBarButton
Try
If RemoveMode = ext_DisconnectMode.ext_dm_UserClosed Then
'User shutdown removed COM Add-in
'Good Housekeeping requires removal of UI
oCommandBars =
Me.OutAddInObj.outlookApp.ActiveExplorer.CommandBars
'Item syntax required
oStandardBar = oCommandBars.Item("Standard")
' In case the button was not deleted, use the existing
one.
oCBB =
CType(oStandardBar.FindControl(Tag:="VB.NETSample"), CommandBarButton)
oCBB.Delete()
Else
'Host shutdown
End If
'DebugWriter("OnDisconnection Called")
OutAddInObj.UnInitHandler()
Catch ex As SystemException
'DebugWriter("OnDisconnection Exception: {0}", ex.Message)
End Try
End Sub
' Return the existing OutAddIn object to the caller
Public Function GetAddin() As OutAddIn
On Error Resume Next
Return Me.OutAddInObj
End Function
End Class
and OutAddIn like this:
Imports Microsoft.Office.Core
imports Extensibility
imports System.Runtime.InteropServices
#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such
as:
' 1) You moved this project to a computer other than which is was
originally created on.
' 2) You chose 'Yes' when presented with a message asking if you wish
to remove the Add-in.
' 3) Registry corruption.
' you will need to re-register the Add-in by building the
reflexionOLSetup project
' by right clicking the project in the Solution Explorer, then choosing
install.
#End Region
<GuidAttribute("CE862D54-3B61-4A79-942E-ABADE3AFDCAF"),
ProgIdAttribute("reflexionOL.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Private OutAddInObj As OutAddIn = New OutAddIn
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
Dim oApp As Outlook.Application
Dim oType As Type
Dim GetProgID As Object
Dim MyProgID As String
Dim oArgs As Object()
Try
'Use InvokeMember to get ProgID of addInInst object
oType = addInInst.GetType
GetProgID = oType.InvokeMember("ProgID", _
Reflection.BindingFlags.Public Or
Reflection.BindingFlags.Public Or Reflection.BindingFlags.GetField Or
Reflection.BindingFlags.GetProperty, _
Nothing, _
addInInst, _
oArgs)
MyProgID = CType(GetProgID, String)
'Convert application from generic object to
Outlook.Application
oApp = CType(application, Outlook.Application)
'Don't call InitHandler if Explorers.Count = 0 and
Inspectors.Count = 0
If oApp.Explorers.Count = 0 And oApp.Inspectors.Count = 0
Then
Exit Sub
End If
'Evaluate ConnectMode
Select Case connectMode
Case ext_ConnectMode.ext_cm_AfterStartup
Case ext_ConnectMode.ext_cm_CommandLine
Case ext_ConnectMode.ext_cm_External
Case ext_ConnectMode.ext_cm_Solution
Case ext_ConnectMode.ext_cm_Startup
Case ext_ConnectMode.ext_cm_UISetup
End Select
' Initialize COMAddin object with this connect object to
allow
' external clients to get access to exposed features
oApp.COMAddIns.Item(MyProgID.ToString).Object = Me
'Call InitHandler
Me.OutAddInobj.InitHandler(oApp, MyProgID)
Catch ex As SystemException
'DebugWriter("OnConnection Exception: {0}", ex.Message)
End Try
End Sub
Private Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
Dim oCommandBars As Office.CommandBars
Dim oStandardBar As Office.CommandBar
Dim oCBB As CommandBarButton
Try
If RemoveMode = ext_DisconnectMode.ext_dm_UserClosed Then
'User shutdown removed COM Add-in
'Good Housekeeping requires removal of UI
oCommandBars =
Me.OutAddInObj.outlookApp.ActiveExplorer.CommandBars
'Item syntax required
oStandardBar = oCommandBars.Item("Standard")
' In case the button was not deleted, use the existing
one.
oCBB =
CType(oStandardBar.FindControl(Tag:="VB.NETSample"), CommandBarButton)
oCBB.Delete()
Else
'Host shutdown
End If
'DebugWriter("OnDisconnection Called")
OutAddInObj.UnInitHandler()
Catch ex As SystemException
'DebugWriter("OnDisconnection Exception: {0}", ex.Message)
End Try
End Sub
' Return the existing OutAddIn object to the caller
Public Function GetAddin() As OutAddIn
On Error Resume Next
Return Me.OutAddInObj
End Function
End Class
References include Outlook 9 and there are'nt any compile or run-time
complaints.
exceptions of any sort. I followed the example from "Outlook Com Add-in
for VB.NET" by microeye which I downloaded from the link in the
Microsoft's article. OnDisconnection does not happen and I also noticed
that the add in does not appear in the Tools|Options|...|COM Add-Ins...
The add-in works as far as it's been implemented with the side effect
of Outlook remaining in memory after UI is gone because add-in never
disconnects. Any ideas? This is rather urgent.
Connect looks like this:
Imports Microsoft.Office.Core
imports Extensibility
imports System.Runtime.InteropServices
#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such
as:
' 1) You moved this project to a computer other than which is was
originally created on.
' 2) You chose 'Yes' when presented with a message asking if you wish
to remove the Add-in.
' 3) Registry corruption.
' you will need to re-register the Add-in by building the
reflexionOLSetup project
' by right clicking the project in the Solution Explorer, then choosing
install.
#End Region
<GuidAttribute("CE862D54-3B61-4A79-942E-ABADE3AFDCAF"),
ProgIdAttribute("reflexionOL.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Private OutAddInObj As OutAddIn = New OutAddIn
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
Dim oApp As Outlook.Application
Dim oType As Type
Dim GetProgID As Object
Dim MyProgID As String
Dim oArgs As Object()
Try
'Use InvokeMember to get ProgID of addInInst object
oType = addInInst.GetType
GetProgID = oType.InvokeMember("ProgID", _
Reflection.BindingFlags.Public Or
Reflection.BindingFlags.Public Or Reflection.BindingFlags.GetField Or
Reflection.BindingFlags.GetProperty, _
Nothing, _
addInInst, _
oArgs)
MyProgID = CType(GetProgID, String)
'Convert application from generic object to
Outlook.Application
oApp = CType(application, Outlook.Application)
'Don't call InitHandler if Explorers.Count = 0 and
Inspectors.Count = 0
If oApp.Explorers.Count = 0 And oApp.Inspectors.Count = 0
Then
Exit Sub
End If
'Evaluate ConnectMode
Select Case connectMode
Case ext_ConnectMode.ext_cm_AfterStartup
Case ext_ConnectMode.ext_cm_CommandLine
Case ext_ConnectMode.ext_cm_External
Case ext_ConnectMode.ext_cm_Solution
Case ext_ConnectMode.ext_cm_Startup
Case ext_ConnectMode.ext_cm_UISetup
End Select
' Initialize COMAddin object with this connect object to
allow
' external clients to get access to exposed features
oApp.COMAddIns.Item(MyProgID.ToString).Object = Me
'Call InitHandler
Me.OutAddInobj.InitHandler(oApp, MyProgID)
Catch ex As SystemException
'DebugWriter("OnConnection Exception: {0}", ex.Message)
End Try
End Sub
Private Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
Dim oCommandBars As Office.CommandBars
Dim oStandardBar As Office.CommandBar
Dim oCBB As CommandBarButton
Try
If RemoveMode = ext_DisconnectMode.ext_dm_UserClosed Then
'User shutdown removed COM Add-in
'Good Housekeeping requires removal of UI
oCommandBars =
Me.OutAddInObj.outlookApp.ActiveExplorer.CommandBars
'Item syntax required
oStandardBar = oCommandBars.Item("Standard")
' In case the button was not deleted, use the existing
one.
oCBB =
CType(oStandardBar.FindControl(Tag:="VB.NETSample"), CommandBarButton)
oCBB.Delete()
Else
'Host shutdown
End If
'DebugWriter("OnDisconnection Called")
OutAddInObj.UnInitHandler()
Catch ex As SystemException
'DebugWriter("OnDisconnection Exception: {0}", ex.Message)
End Try
End Sub
' Return the existing OutAddIn object to the caller
Public Function GetAddin() As OutAddIn
On Error Resume Next
Return Me.OutAddInObj
End Function
End Class
and OutAddIn like this:
Imports Microsoft.Office.Core
imports Extensibility
imports System.Runtime.InteropServices
#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such
as:
' 1) You moved this project to a computer other than which is was
originally created on.
' 2) You chose 'Yes' when presented with a message asking if you wish
to remove the Add-in.
' 3) Registry corruption.
' you will need to re-register the Add-in by building the
reflexionOLSetup project
' by right clicking the project in the Solution Explorer, then choosing
install.
#End Region
<GuidAttribute("CE862D54-3B61-4A79-942E-ABADE3AFDCAF"),
ProgIdAttribute("reflexionOL.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Private OutAddInObj As OutAddIn = New OutAddIn
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
Dim oApp As Outlook.Application
Dim oType As Type
Dim GetProgID As Object
Dim MyProgID As String
Dim oArgs As Object()
Try
'Use InvokeMember to get ProgID of addInInst object
oType = addInInst.GetType
GetProgID = oType.InvokeMember("ProgID", _
Reflection.BindingFlags.Public Or
Reflection.BindingFlags.Public Or Reflection.BindingFlags.GetField Or
Reflection.BindingFlags.GetProperty, _
Nothing, _
addInInst, _
oArgs)
MyProgID = CType(GetProgID, String)
'Convert application from generic object to
Outlook.Application
oApp = CType(application, Outlook.Application)
'Don't call InitHandler if Explorers.Count = 0 and
Inspectors.Count = 0
If oApp.Explorers.Count = 0 And oApp.Inspectors.Count = 0
Then
Exit Sub
End If
'Evaluate ConnectMode
Select Case connectMode
Case ext_ConnectMode.ext_cm_AfterStartup
Case ext_ConnectMode.ext_cm_CommandLine
Case ext_ConnectMode.ext_cm_External
Case ext_ConnectMode.ext_cm_Solution
Case ext_ConnectMode.ext_cm_Startup
Case ext_ConnectMode.ext_cm_UISetup
End Select
' Initialize COMAddin object with this connect object to
allow
' external clients to get access to exposed features
oApp.COMAddIns.Item(MyProgID.ToString).Object = Me
'Call InitHandler
Me.OutAddInobj.InitHandler(oApp, MyProgID)
Catch ex As SystemException
'DebugWriter("OnConnection Exception: {0}", ex.Message)
End Try
End Sub
Private Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
Dim oCommandBars As Office.CommandBars
Dim oStandardBar As Office.CommandBar
Dim oCBB As CommandBarButton
Try
If RemoveMode = ext_DisconnectMode.ext_dm_UserClosed Then
'User shutdown removed COM Add-in
'Good Housekeeping requires removal of UI
oCommandBars =
Me.OutAddInObj.outlookApp.ActiveExplorer.CommandBars
'Item syntax required
oStandardBar = oCommandBars.Item("Standard")
' In case the button was not deleted, use the existing
one.
oCBB =
CType(oStandardBar.FindControl(Tag:="VB.NETSample"), CommandBarButton)
oCBB.Delete()
Else
'Host shutdown
End If
'DebugWriter("OnDisconnection Called")
OutAddInObj.UnInitHandler()
Catch ex As SystemException
'DebugWriter("OnDisconnection Exception: {0}", ex.Message)
End Try
End Sub
' Return the existing OutAddIn object to the caller
Public Function GetAddin() As OutAddIn
On Error Resume Next
Return Me.OutAddInObj
End Function
End Class
References include Outlook 9 and there are'nt any compile or run-time
complaints.