Temp control remains on commandbar

Add-in Express™ Support Service
That's what is more important than anything else

Temp control remains on commandbar
 
serhat adali




Posts: 5
Joined: 2006-01-26
Hi there,

I am adding a temprory button to the new mail inspector by hooking to new inspector open event.

For some reason, when my default mail editor is MS Word, button does not dissappear after closing the inspector, or even Outlook. When I try to delete it or make it invisible from the code in OnBeginShutDown method, I receive that strange HResult0x800... exception. When I start Word externally, I can still see the button.

Any suggestions?

Thanks in advance,
Serhat.

Private Sub NewInspector_Open(ByVal inspTarget As Outlook.Inspector)
If (TypeOf (inspTarget.CurrentItem) Is Outlook.MailItem) Then
'Get standard commandbar of the contact form and pass to modifycommandbar.
Dim bars As Office.CommandBars = inspTarget.CommandBars
Dim cmdbarTarget As Office.CommandBar = bars.Item(1)
Dim oMissing As Object = Type.Missing
Try
oButtonProcessOutbound = cmdbarTarget.Controls("asd")
Catch ex As System.Exception

oButtonProcessOutbound = cmdbarTarget.Controls.Add(MsoControlType.msoControlButton, oMissing, oMissing, oMissing, True)
' Set button caption and tag.
oButtonProcessOutbound.Style = MsoButtonStyle.msoButtonCaption
oButtonProcessOutbound.Caption = "asd"
oButtonProcessOutbound.Tag = "asd"
Finally
' Set visibility and add eventhandler
oButtonProcessOutbound.Visible = True
AddHandler oButtonProcessOutbound.Click, AddressOf oButtonProcessOutbound_Click
End Try
End If

-------------------

If Not securityManager1 Is Nothing Then
If securityManager1.DisableOOMWarnings = True Then securityManager1.DisableOOMWarnings = False
End If

Try
RemoveHandler inspectors.NewInspector, AddressOf NewInspector_Open
Catch
End Try

If Not inspectors Is Nothing Then
Marshal.ReleaseComObject(inspectors)
End If

If Not oButtonProcessOutbound Is Nothing Then
Try
oButtonProcessOutbound.Visible = False
Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
Marshal.ReleaseComObject(oButtonProcessOutbound)
End If
Posted 08 May, 2006 07:33:39 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Serhat.

If you add controls to built-in command bars, Word stores its command bars and controls in templates (e.g. Normal.dot) regardless whether you add a temprary control or not. That is why you still see the button after Outlook closes. You can't make the button invisible in the OnBeginShutDown method because the button is already disconnected from Word. Try to hide the button in the InspectorActivate or InspectorClose event handlers. We have solutions on how to show command bars for Outlook, hide them for Word and vice versa. You can download it here:
http://www.add-in-express.com/projects/wordandoutlookissue.zip
http://www.add-in-express.com/projects/wordinoutlook2.zip
Posted 08 May, 2006 15:30:58 Top