By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,131 Members | 1,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,131 IT Pros & Developers. It's quick & easy.

outlook hangs with COM add-in

P: n/a
Help! I created a COM addin using vb.net based on the KB article
302896 (http://support.microsoft.com/default...;en-us;302896).
The problem is Outlook remains in memory when after it. I know the
problem is in the OnStartupComplete function. If I comment this
function out, Outlook closes properly. I have added a GC.Collect at
the end, but that doesn't work either. I don't thing the
"oCommandBars = Nothing" is actually getting rid of the CommandBar,
but I'm not sure. Here is the code that makes outlook hang (Straight
from the Knowledge Base):

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete

Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar

On Error Resume Next
' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer
object.
oCommandBars =
applicationObject.ActiveExplorer.CommandBars
End If

oStandardBar = oCommandBars.Item("Standard")
If oStandardBar Is Nothing Then
' Access names its main toolbar Database.

oStandardBar = oCommandBars.Item("Database")

End If

' In case the button was not deleted, use the exiting one.
MyButton = oStandardBar.Controls.Item("My Custom Button")
If MyButton Is Nothing Then

MyButton = oStandardBar.Controls.Add(1)
With MyButton
.Caption = "My Custom Button"
.Style = MsoButtonStyle.msoButtonCaption

' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when more than
' one application window is visible. The property is
required
' by some Office applications and should be provided.

.Tag = "My Custom Button"

' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, so
that if
' the add-in is not loaded when a user clicks the
button,
' MSO loads the add-in automatically and then raises
' the Click event for the add-in to handle.

.OnAction = "!<MyCOMAddin.Connect>"

.Visible = True
End With
End If

' Display a simple message to show which application you
started in.
MsgBox("Started in " & applicationObject.Name & ".")
oStandardBar = Nothing
oCommandBars = Nothing
End Sub
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Damian,
Have you tried using System.Runtime.InteropServices.Marshal.ReleaseComO bject
on each of the Outlook objects to ensure that your .NET based add-in has
release all the Outlook objects?

Hope this helps
Jay

"damian" <de**************@spamgourmet.com> wrote in message
news:bc**************************@posting.google.c om...
Help! I created a COM addin using vb.net based on the KB article
302896 (http://support.microsoft.com/default...;en-us;302896).
The problem is Outlook remains in memory when after it. I know the
problem is in the OnStartupComplete function. If I comment this
function out, Outlook closes properly. I have added a GC.Collect at
the end, but that doesn't work either. I don't thing the
"oCommandBars = Nothing" is actually getting rid of the CommandBar,
but I'm not sure. Here is the code that makes outlook hang (Straight
from the Knowledge Base):

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete

Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar

On Error Resume Next
' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer
object.
oCommandBars =
applicationObject.ActiveExplorer.CommandBars
End If

oStandardBar = oCommandBars.Item("Standard")
If oStandardBar Is Nothing Then
' Access names its main toolbar Database.

oStandardBar = oCommandBars.Item("Database")

End If

' In case the button was not deleted, use the exiting one.
MyButton = oStandardBar.Controls.Item("My Custom Button")
If MyButton Is Nothing Then

MyButton = oStandardBar.Controls.Add(1)
With MyButton
.Caption = "My Custom Button"
.Style = MsoButtonStyle.msoButtonCaption

' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when more than
' one application window is visible. The property is
required
' by some Office applications and should be provided.

.Tag = "My Custom Button"

' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, so
that if
' the add-in is not loaded when a user clicks the
button,
' MSO loads the add-in automatically and then raises
' the Click event for the add-in to handle.

.OnAction = "!<MyCOMAddin.Connect>"

.Visible = True
End With
End If

' Display a simple message to show which application you
started in.
MsgBox("Started in " & applicationObject.Name & ".")
oStandardBar = Nothing
oCommandBars = Nothing
End Sub

Nov 20 '05 #2

P: n/a
No I haven't. Could you please give me an example of how to do that? Thanks.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:<u$*************@TK2MSFTNGP11.phx.gbl>...
Damian,
Have you tried using System.Runtime.InteropServices.Marshal.ReleaseComO bject
on each of the Outlook objects to ensure that your .NET based add-in has
release all the Outlook objects?

Hope this helps
Jay

"damian" <de**************@spamgourmet.com> wrote in message
news:bc**************************@posting.google.c om...
Help! I created a COM addin using vb.net based on the KB article
302896 (http://support.microsoft.com/default...;en-us;302896).
The problem is Outlook remains in memory when after it. I know the
problem is in the OnStartupComplete function. If I comment this
function out, Outlook closes properly. I have added a GC.Collect at
the end, but that doesn't work either. I don't thing the
"oCommandBars = Nothing" is actually getting rid of the CommandBar,
but I'm not sure. Here is the code that makes outlook hang (Straight
from the Knowledge Base):

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete

Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar

On Error Resume Next
' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer
object.
oCommandBars =
applicationObject.ActiveExplorer.CommandBars
End If

oStandardBar = oCommandBars.Item("Standard")
If oStandardBar Is Nothing Then
' Access names its main toolbar Database.

oStandardBar = oCommandBars.Item("Database")

End If

' In case the button was not deleted, use the exiting one.
MyButton = oStandardBar.Controls.Item("My Custom Button")
If MyButton Is Nothing Then

MyButton = oStandardBar.Controls.Add(1)
With MyButton
.Caption = "My Custom Button"
.Style = MsoButtonStyle.msoButtonCaption

' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when more than
' one application window is visible. The property is
required
' by some Office applications and should be provided.

.Tag = "My Custom Button"

' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, so
that if
' the add-in is not loaded when a user clicks the
button,
' MSO loads the add-in automatically and then raises
' the Click event for the add-in to handle.

.OnAction = "!<MyCOMAddin.Connect>"

.Visible = True
End With
End If

' Display a simple message to show which application you
started in.
MsgBox("Started in " & applicationObject.Name & ".")
oStandardBar = Nothing
oCommandBars = Nothing
End Sub

Nov 20 '05 #3

P: n/a
Damian,
Did you try looking up ReleaseComObject in the help?

Here are a couple of links to sample Outlook Add-ins that use
ReleaseComObject.

http://msdn.microsoft.com/library/de...addinvbnet.asp

http://msdn.microsoft.com/library/de...hatsNew2k3.asp

Hope this helps
Jay
"damian" <de**************@spamgourmet.com> wrote in message
news:bc**************************@posting.google.c om...
No I haven't. Could you please give me an example of how to do that? Thanks.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message

news:<u$*************@TK2MSFTNGP11.phx.gbl>...
Damian,
Have you tried using System.Runtime.InteropServices.Marshal.ReleaseComO bject on each of the Outlook objects to ensure that your .NET based add-in has
release all the Outlook objects?

Hope this helps
Jay

"damian" <de**************@spamgourmet.com> wrote in message
news:bc**************************@posting.google.c om...
Help! I created a COM addin using vb.net based on the KB article
302896 (http://support.microsoft.com/default...;en-us;302896). The problem is Outlook remains in memory when after it. I know the
problem is in the OnStartupComplete function. If I comment this
function out, Outlook closes properly. I have added a GC.Collect at
the end, but that doesn't work either. I don't thing the
"oCommandBars = Nothing" is actually getting rid of the CommandBar,
but I'm not sure. Here is the code that makes outlook hang (Straight
from the Knowledge Base):

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete

Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar

On Error Resume Next
' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer
object.
oCommandBars =
applicationObject.ActiveExplorer.CommandBars
End If

oStandardBar = oCommandBars.Item("Standard")
If oStandardBar Is Nothing Then
' Access names its main toolbar Database.

oStandardBar = oCommandBars.Item("Database")

End If

' In case the button was not deleted, use the exiting one.
MyButton = oStandardBar.Controls.Item("My Custom Button")
If MyButton Is Nothing Then

MyButton = oStandardBar.Controls.Add(1)
With MyButton
.Caption = "My Custom Button"
.Style = MsoButtonStyle.msoButtonCaption

' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when more than
' one application window is visible. The property is
required
' by some Office applications and should be provided.

.Tag = "My Custom Button"

' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, so
that if
' the add-in is not loaded when a user clicks the
button,
' MSO loads the add-in automatically and then raises
' the Click event for the add-in to handle.

.OnAction = "!<MyCOMAddin.Connect>"

.Visible = True
End With
End If

' Display a simple message to show which application you
started in.
MsgBox("Started in " & applicationObject.Name & ".")
oStandardBar = Nothing
oCommandBars = Nothing
End Sub

Nov 20 '05 #4

P: n/a
I actually have tried this, but it never worked. I always ran into a
problem with this line: Imports Outlook =
Microsoft.Office.Interop.Outlook

I added Microsoft Outlook 9.0 Object Library, not 10.0. I am dealing
with Outlook 2000. I'm guessing that's what causes the import
problem. I also had a problem with the article because you cannot
download the sample through the link (odc_oladdinvbnet.exe), it is
very frustrating.

Another interesting note is this. I cannot get Outlook 2000 to
shutdown properly when I add a custom button based off of article
302896. However, when I use article 302896 at home with Outlook XP,
it does work. Does this make sense?

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:<OX**************@TK2MSFTNGP10.phx.gbl>...
Damian,
Did you try looking up ReleaseComObject in the help?

Here are a couple of links to sample Outlook Add-ins that use
ReleaseComObject.

http://msdn.microsoft.com/library/de...addinvbnet.asp

http://msdn.microsoft.com/library/de...hatsNew2k3.asp

Hope this helps
Jay
"damian" <de**************@spamgourmet.com> wrote in message
news:bc**************************@posting.google.c om...
No I haven't. Could you please give me an example of how to do that?

Thanks.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message

news:<u$*************@TK2MSFTNGP11.phx.gbl>...
Damian,
Have you tried using System.Runtime.InteropServices.Marshal.ReleaseComO bject on each of the Outlook objects to ensure that your .NET based add-in has
release all the Outlook objects?

Hope this helps
Jay

"damian" <de**************@spamgourmet.com> wrote in message
news:bc**************************@posting.google.c om...
> Help! I created a COM addin using vb.net based on the KB article
> 302896 (http://support.microsoft.com/default...;en-us;302896). > The problem is Outlook remains in memory when after it. I know the
> problem is in the OnStartupComplete function. If I comment this
> function out, Outlook closes properly. I have added a GC.Collect at
> the end, but that doesn't work either. I don't thing the
> "oCommandBars = Nothing" is actually getting rid of the CommandBar,
> but I'm not sure. Here is the code that makes outlook hang (Straight
> from the Knowledge Base):
>
> Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
> Extensibility.IDTExtensibility2.OnStartupComplete
>
> Dim oCommandBars As CommandBars
> Dim oStandardBar As CommandBar
>
> On Error Resume Next
> ' Set up a custom button on the "Standard" command bar.
> oCommandBars = applicationObject.CommandBars
> If oCommandBars Is Nothing Then
> ' Outlook has the CommandBars collection on the Explorer
> object.
> oCommandBars =
> applicationObject.ActiveExplorer.CommandBars
> End If
>
> oStandardBar = oCommandBars.Item("Standard")
> If oStandardBar Is Nothing Then
> ' Access names its main toolbar Database.
>
> oStandardBar = oCommandBars.Item("Database")
>
> End If
>
> ' In case the button was not deleted, use the exiting one.
> MyButton = oStandardBar.Controls.Item("My Custom Button")
> If MyButton Is Nothing Then
>
> MyButton = oStandardBar.Controls.Add(1)
> With MyButton
> .Caption = "My Custom Button"
> .Style = MsoButtonStyle.msoButtonCaption
>
> ' The following items are optional, but recommended.
> ' The Tag property lets you quickly find the control
> ' and helps MSO keep track of it when more than
> ' one application window is visible. The property is
> required
> ' by some Office applications and should be provided.
>
> .Tag = "My Custom Button"
>
> ' The OnAction property is optional but recommended.
> ' It should be set to the ProgID of the add-in, so
> that if
> ' the add-in is not loaded when a user clicks the
> button,
> ' MSO loads the add-in automatically and then raises
> ' the Click event for the add-in to handle.
>
> .OnAction = "!<MyCOMAddin.Connect>"
>
> .Visible = True
> End With
> End If
>
> ' Display a simple message to show which application you
> started in.
> MsgBox("Started in " & applicationObject.Name & ".")
>
>
> oStandardBar = Nothing
> oCommandBars = Nothing
>
>
> End Sub

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.