S
steven.shannon
Hey all,
Apologies for the ensuing long-winded post, but I want to be as clear
as I can about what's going on.
I have a COM addin that was developed for Outlook 2002/XP and later.
It began in VBA but was eventually wholly migrated to .NET in order to
incorporate XML web services which are an integral part of it. It's
supposed to create a new button in the standard Outlook toolbar that
runs the program (which acts like a standard wizard tool). Most
clients report no problem with the install, but a few have reported
that the button doesn't show up when they install the addin, and there
doesn't seem to be any consistency as to what versions of Windows or
Outlook they are running. (i.e. the issue has occurred on a Windows
2000 machine as well as XP). The frustrating part is that, up until
recently, I've been completely unable to replicate the issue in-house.
However, I recently dug out an old laptop running Windows 2000 and
Outlook 2002, and after attempting to install the addin I finally see
what the client sees. The addin does in fact get added to the COM Add-
ins list in Outlook, and the box is checked, but the button does not
appear in the toolbar. I've checked the registry, and the correct
entries are added into HKCU and HKCR. Comparing the registry settings
on another machine where the addin installs just fine, they are
identical from what I can tell. If I uncheck and re-check the box in
the addins list, a runtime error occurs and the LoadBehavior key in
the registry switches from 3 to 2.
After compiling a few different test versions of the addin with print
statements in various places, I've determined that the OnConnection
event is firing successfully. Also, the OnStartupComplete event will
fire with a print statement there and nothing else. However, the
moment I add the first piece of the code that loads the button into
the toolbar, the addin no longer works. Anything related to the
ActiveExplorer will kill the addin silently upon loading. No amount
of try/catching or if/elsing will prevent the failure, and print
statements no longer get executed no matter where they're placed in
OnStartupComplete.
Now, if I forget about trying to load the button into the toolbar and
instead call my code directly from the OnConnection event, the program
itself comes up and works flawlessly as soon as the user opens
Outlook. Of course, once they close the program, it becomes
unavailable until they restart Outlook because there's no button,
which is less than ideal. But it at least shows that the code itself
isn't the problem. There seems to be some kind of malfunction when
trying to access the ActiveExplorer, almost as if it doesn't exist at
the point which it's being called.
Outlook itself is not being opened via ActiveSync or any other method
that I'm aware of -- I'm just opening it like any of us would, so
there should be a UI available, yes? I've pin-pointed exactly where
the addin fails to load, but I'm completely lost as to how I should
get around this. Below is my code from the Connect class -- there's
nothing terribly different about it from what I've seen in other
posts, but maybe there's something blaring there that I'm missing.
Any assistance that ANYONE can give at this point would be most
appreciated.
Thank you all in advance,
Steve
=========================================
Imports Microsoft.Office.Core
Imports Extensibility
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core.MsoControlType
Imports Microsoft.Office.Core.MsoBarPosition
Imports Microsoft.Office.Core.MsoButtonStyle
Imports Microsoft.Office.Core.MsoFileDialogType
Imports Microsoft.Office.Core.MsoFileDialogView
Imports Microsoft.Office.Core.MsoTriState
<GuidAttribute("5ccfec6f-5ea3-48d6-92ac-192842cf866b"),
ProgIdAttribute("MyWizard.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Dim applicationObject As Object
Dim addInInstance As Object
Dim WithEvents objCommandBarButton As CommandBarButton
Public Sub OnBeginShutdown(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnBeginShutdown
'On Error Resume Next
objCommandBarButton.Delete()
objCommandBarButton = Nothing
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
DisplayMsgBox("on startup complete running")
'DisplayMsgBox("on startup complete running")
Dim objCommandBars As CommandBars
Dim objCommandBar As CommandBar
Dim objCommandBarControl As CommandBarControl
' Create a menu command on the "Tools" menu.
Try
objCommandBars =
applicationObject.ActiveExplorer.CommandBars
'DisplayMsgBox("menu command works")
Catch ex As Exception
'DisplayMsgBox(ex.Message)
objCommandBars = applicationObject.CommandBars
End Try
Try
objCommandBar = objCommandBars.Item("Standard")
'DisplayMsgBox("standard menu works")
Catch ex As Exception
objCommandBar = objCommandBars.Add("MyWizard",
msoBarFloating, , True)
'DisplayMsgBox("floating menu should be created")
End Try
objCommandBar.Visible = True
'Make sure menu command doesn't already exist.
For Each objCommandBarControl In objCommandBar.Controls
If objCommandBarControl.Caption = "MyWizard" Then
objCommandBar.Controls.Item("MyWizard").Delete()
End If
Next objCommandBarControl
objCommandBarButton =
objCommandBar.Controls.Add(msoControlButton, , , , True)
With objCommandBarButton
.Caption = "MyWizard"
.Style = msoButtonCaption
.Tag = "MyWizard"
.OnAction = "<!MyWizard.Connect>"
.Visible = True
End With
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
On Error Resume Next
' Disconnect the shared add-in, no matter how the host
application
' was shut down.
If RemoveMode <>
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
Call OnBeginShutdown(custom)
applicationObject = Nothing
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
applicationObject = application
addInInstance = addInInst
' No matter how the host application started, connect the
shared add-in.
If (connectMode <>
Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
Call OnStartupComplete(custom)
End Sub
Private Sub objCommandBarButton_Click(ByVal Ctrl As
CommandBarButton, _
ByRef CancelDefault As Boolean) Handles
objCommandBarButton.Click
' These are the two functions that initialize the wizard.
' The program works fine when these are called from
OnConnection.
ConfigureEnv()
RunPasswordForm()
End Sub
End Class
=========================================
Apologies for the ensuing long-winded post, but I want to be as clear
as I can about what's going on.
I have a COM addin that was developed for Outlook 2002/XP and later.
It began in VBA but was eventually wholly migrated to .NET in order to
incorporate XML web services which are an integral part of it. It's
supposed to create a new button in the standard Outlook toolbar that
runs the program (which acts like a standard wizard tool). Most
clients report no problem with the install, but a few have reported
that the button doesn't show up when they install the addin, and there
doesn't seem to be any consistency as to what versions of Windows or
Outlook they are running. (i.e. the issue has occurred on a Windows
2000 machine as well as XP). The frustrating part is that, up until
recently, I've been completely unable to replicate the issue in-house.
However, I recently dug out an old laptop running Windows 2000 and
Outlook 2002, and after attempting to install the addin I finally see
what the client sees. The addin does in fact get added to the COM Add-
ins list in Outlook, and the box is checked, but the button does not
appear in the toolbar. I've checked the registry, and the correct
entries are added into HKCU and HKCR. Comparing the registry settings
on another machine where the addin installs just fine, they are
identical from what I can tell. If I uncheck and re-check the box in
the addins list, a runtime error occurs and the LoadBehavior key in
the registry switches from 3 to 2.
After compiling a few different test versions of the addin with print
statements in various places, I've determined that the OnConnection
event is firing successfully. Also, the OnStartupComplete event will
fire with a print statement there and nothing else. However, the
moment I add the first piece of the code that loads the button into
the toolbar, the addin no longer works. Anything related to the
ActiveExplorer will kill the addin silently upon loading. No amount
of try/catching or if/elsing will prevent the failure, and print
statements no longer get executed no matter where they're placed in
OnStartupComplete.
Now, if I forget about trying to load the button into the toolbar and
instead call my code directly from the OnConnection event, the program
itself comes up and works flawlessly as soon as the user opens
Outlook. Of course, once they close the program, it becomes
unavailable until they restart Outlook because there's no button,
which is less than ideal. But it at least shows that the code itself
isn't the problem. There seems to be some kind of malfunction when
trying to access the ActiveExplorer, almost as if it doesn't exist at
the point which it's being called.
Outlook itself is not being opened via ActiveSync or any other method
that I'm aware of -- I'm just opening it like any of us would, so
there should be a UI available, yes? I've pin-pointed exactly where
the addin fails to load, but I'm completely lost as to how I should
get around this. Below is my code from the Connect class -- there's
nothing terribly different about it from what I've seen in other
posts, but maybe there's something blaring there that I'm missing.
Any assistance that ANYONE can give at this point would be most
appreciated.
Thank you all in advance,
Steve
=========================================
Imports Microsoft.Office.Core
Imports Extensibility
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core.MsoControlType
Imports Microsoft.Office.Core.MsoBarPosition
Imports Microsoft.Office.Core.MsoButtonStyle
Imports Microsoft.Office.Core.MsoFileDialogType
Imports Microsoft.Office.Core.MsoFileDialogView
Imports Microsoft.Office.Core.MsoTriState
<GuidAttribute("5ccfec6f-5ea3-48d6-92ac-192842cf866b"),
ProgIdAttribute("MyWizard.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Dim applicationObject As Object
Dim addInInstance As Object
Dim WithEvents objCommandBarButton As CommandBarButton
Public Sub OnBeginShutdown(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnBeginShutdown
'On Error Resume Next
objCommandBarButton.Delete()
objCommandBarButton = Nothing
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
DisplayMsgBox("on startup complete running")
'DisplayMsgBox("on startup complete running")
Dim objCommandBars As CommandBars
Dim objCommandBar As CommandBar
Dim objCommandBarControl As CommandBarControl
' Create a menu command on the "Tools" menu.
Try
objCommandBars =
applicationObject.ActiveExplorer.CommandBars
'DisplayMsgBox("menu command works")
Catch ex As Exception
'DisplayMsgBox(ex.Message)
objCommandBars = applicationObject.CommandBars
End Try
Try
objCommandBar = objCommandBars.Item("Standard")
'DisplayMsgBox("standard menu works")
Catch ex As Exception
objCommandBar = objCommandBars.Add("MyWizard",
msoBarFloating, , True)
'DisplayMsgBox("floating menu should be created")
End Try
objCommandBar.Visible = True
'Make sure menu command doesn't already exist.
For Each objCommandBarControl In objCommandBar.Controls
If objCommandBarControl.Caption = "MyWizard" Then
objCommandBar.Controls.Item("MyWizard").Delete()
End If
Next objCommandBarControl
objCommandBarButton =
objCommandBar.Controls.Add(msoControlButton, , , , True)
With objCommandBarButton
.Caption = "MyWizard"
.Style = msoButtonCaption
.Tag = "MyWizard"
.OnAction = "<!MyWizard.Connect>"
.Visible = True
End With
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
On Error Resume Next
' Disconnect the shared add-in, no matter how the host
application
' was shut down.
If RemoveMode <>
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
Call OnBeginShutdown(custom)
applicationObject = Nothing
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
applicationObject = application
addInInstance = addInInst
' No matter how the host application started, connect the
shared add-in.
If (connectMode <>
Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
Call OnStartupComplete(custom)
End Sub
Private Sub objCommandBarButton_Click(ByVal Ctrl As
CommandBarButton, _
ByRef CancelDefault As Boolean) Handles
objCommandBarButton.Click
' These are the two functions that initialize the wizard.
' The program works fine when these are called from
OnConnection.
ConfigureEnv()
RunPasswordForm()
End Sub
End Class
=========================================