outlook hangs with COM add-in

D

damian

Help! I created a COM addin using vb.net based on the KB article
302896 (http://support.microsoft.com/default.aspx?scid=kb;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
 
J

Jay B. Harlow [MVP - Outlook]

Damian,
Have you tried using System.Runtime.InteropServices.Marshal.ReleaseComObject
on each of the Outlook objects to ensure that your .NET based add-in has
release all the Outlook objects?

Hope this helps
Jay
 
J

Jay B. Harlow [MVP - Outlook]

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/default.asp?url=/library/en-us/dnout2k2/html/odc_oladdinvbnet.asp

http://msdn.microsoft.com/library/d...n-us/odc_ol2003_ta/html/odc_OLWhatsNew2k3.asp

Hope this helps
Jay


damian said:
No I haven't. Could you please give me an example of how to do that? Thanks.

"Jay B. Harlow [MVP - Outlook]" <[email protected]> wrote in message
Damian,
Have you tried using System.Runtime.InteropServices.Marshal.ReleaseComObject
on each of the Outlook objects to ensure that your .NET based add-in has
release all the Outlook objects?

Hope this helps
Jay
 
D

damian

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 said:
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/default.asp?url=/library/en-us/dnout2k2/html/odc_oladdinvbnet.asp

http://msdn.microsoft.com/library/d...n-us/odc_ol2003_ta/html/odc_OLWhatsNew2k3.asp

Hope this helps
Jay


damian said:
No I haven't. Could you please give me an example of how to do that? Thanks.

"Jay B. Harlow [MVP - Outlook]" <[email protected]> wrote in message
Damian,
Have you tried using System.Runtime.InteropServices.Marshal.ReleaseComObject
on each of the Outlook objects to ensure that your .NET based add-in has
release all the Outlook objects?

Hope this helps
Jay

Help! I created a COM addin using vb.net based on the KB article
302896 (http://support.microsoft.com/default.aspx?scid=kb;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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top