B
Bjørn Eliasen
Hi.
I have been working with this problem intensively. Below please find some
sample code which has the unwanted behavior. Compile and install the code
(the problem does not show when debugging), open a mail item, and then close
Outlook without closing the mail item. Outlook will now hang. Any
suggestions will be highly appriciated.
I use vb 6.0 and Outlook 2003 but the problem also shows in Outlook XP.
The code below is based on the Outlook Comm add-in template from Micro Eye
Inc. Thanks to Micro Eye Inc.
Best regards, Bjørn
Code:
In Connect.dsr (From MicroEye COM Add-in template, Unchanged):
Option Explicit
Private gBaseClass As New OutAddIn
Private Sub AddinInstance_OnAddInsUpdate(custom() As Variant)
'DebugWrite "AddinInstance_OnAddInsUpdate"
End Sub
Private Sub AddinInstance_OnBeginShutdown(custom() As Variant)
'
'DebugWrite "AddinInstance_OnBeginShutdown"
End Sub
Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
On Error Resume Next
'Evaluate ConnectMode
Select Case ConnectMode
Case ext_cm_Startup
Case ext_cm_AfterStartup
Case ext_cm_CommandLine
Case ext_cm_Startup
End Select
If Application.Explorers.Count = 0 And Application.Inspectors.Count = 0
Then
Exit Sub
End If
gBaseClass.InitHandler Application, AddInInst.ProgId
End Sub
Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
gBaseClass.UnInitHandler
If RemoveMode = ext_dm_UserClosed Then
Else
End If
Set gBaseClass = Nothing
End Sub
Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
'DebugWrite "AddinInstance OnStartupComplete"
End Sub
In OutAddIn.cls
Option Explicit
Private WithEvents objOutlook As Outlook.Application
Private WithEvents objNS As Outlook.NameSpace
Private WithEvents objExpl As Outlook.Explorer
Private WithEvents colExpl As Outlook.Explorers
Private WithEvents objInsp As Outlook.inspector
Private WithEvents colInsp As Outlook.Inspectors
Private WithEvents objMailItem As Outlook.MailItem
Friend Sub InitHandler(olApp As Outlook.Application, strProgID As String)
Set objOutlook = olApp 'Application Object
Set m_olApp = olApp
Set objNS = objOutlook.GetNamespace("MAPI") 'NameSpace Object
Set colExpl = objOutlook.Explorers 'Explorers Object
Set colInsp = objOutlook.Inspectors 'Inspectors Object
Set objExpl = objOutlook.ActiveExplorer 'Explorer Object
End Sub
Friend Sub UnInitHandler()
Set objInsp = Nothing
Set objExpl = Nothing
Set objMailItem = Nothing
Set colInsp = Nothing
Set colExpl = Nothing
Set objNS = Nothing
Set m_olApp = Nothing
Set objOutlook = Nothing
End Sub
Private Sub colExpl_NewExplorer(ByVal Explorer As Outlook.Explorer)
If objExpl Is Nothing Then
Set objExpl = Explorer
End If
End Sub
Private Sub colInsp_NewInspector(ByVal inspector As inspector)
Dim objItem As Object
On Error GoTo 0
Set objInsp = inspector
Set objItem = objInsp.CurrentItem
Select Case objItem.Class
Case olMail
Set objMailItem = objItem
Case Else
End Select
End Sub
Private Sub objExpl_BeforeFolderSwitch(ByVal NewFolder As Object, Cancel As
Boolean)
On Error Resume Next
End Sub
Private Sub objExpl_Close()
Set objExpl = m_olApp.ActiveExplorer
If (objExpl Is Nothing) And _
(m_olApp.Inspectors.Count = 0) Then
UnInitHandler
End If
End Sub
Private Sub objInsp_Close()
If m_olApp.ActiveExplorer Is Nothing And _
m_olApp.Inspectors.Count <= 1 Then
UnInitHandler
End If
Set objInsp = Nothing
End Sub
Private Sub objMailItem_Close(Cancel As Boolean)
frmTest.Show 1 ' This is where Outlook hangs
End Sub
In Module modOutlook.bas
Option Explicit
Public m_olApp As Outlook.Application
In frmTest.frm with one button named brOK:
Private Sub btOk_Click()
Unload Me
End Sub
I have been working with this problem intensively. Below please find some
sample code which has the unwanted behavior. Compile and install the code
(the problem does not show when debugging), open a mail item, and then close
Outlook without closing the mail item. Outlook will now hang. Any
suggestions will be highly appriciated.
I use vb 6.0 and Outlook 2003 but the problem also shows in Outlook XP.
The code below is based on the Outlook Comm add-in template from Micro Eye
Inc. Thanks to Micro Eye Inc.
Best regards, Bjørn
Code:
In Connect.dsr (From MicroEye COM Add-in template, Unchanged):
Option Explicit
Private gBaseClass As New OutAddIn
Private Sub AddinInstance_OnAddInsUpdate(custom() As Variant)
'DebugWrite "AddinInstance_OnAddInsUpdate"
End Sub
Private Sub AddinInstance_OnBeginShutdown(custom() As Variant)
'
'DebugWrite "AddinInstance_OnBeginShutdown"
End Sub
Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
On Error Resume Next
'Evaluate ConnectMode
Select Case ConnectMode
Case ext_cm_Startup
Case ext_cm_AfterStartup
Case ext_cm_CommandLine
Case ext_cm_Startup
End Select
If Application.Explorers.Count = 0 And Application.Inspectors.Count = 0
Then
Exit Sub
End If
gBaseClass.InitHandler Application, AddInInst.ProgId
End Sub
Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
gBaseClass.UnInitHandler
If RemoveMode = ext_dm_UserClosed Then
Else
End If
Set gBaseClass = Nothing
End Sub
Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
'DebugWrite "AddinInstance OnStartupComplete"
End Sub
In OutAddIn.cls
Option Explicit
Private WithEvents objOutlook As Outlook.Application
Private WithEvents objNS As Outlook.NameSpace
Private WithEvents objExpl As Outlook.Explorer
Private WithEvents colExpl As Outlook.Explorers
Private WithEvents objInsp As Outlook.inspector
Private WithEvents colInsp As Outlook.Inspectors
Private WithEvents objMailItem As Outlook.MailItem
Friend Sub InitHandler(olApp As Outlook.Application, strProgID As String)
Set objOutlook = olApp 'Application Object
Set m_olApp = olApp
Set objNS = objOutlook.GetNamespace("MAPI") 'NameSpace Object
Set colExpl = objOutlook.Explorers 'Explorers Object
Set colInsp = objOutlook.Inspectors 'Inspectors Object
Set objExpl = objOutlook.ActiveExplorer 'Explorer Object
End Sub
Friend Sub UnInitHandler()
Set objInsp = Nothing
Set objExpl = Nothing
Set objMailItem = Nothing
Set colInsp = Nothing
Set colExpl = Nothing
Set objNS = Nothing
Set m_olApp = Nothing
Set objOutlook = Nothing
End Sub
Private Sub colExpl_NewExplorer(ByVal Explorer As Outlook.Explorer)
If objExpl Is Nothing Then
Set objExpl = Explorer
End If
End Sub
Private Sub colInsp_NewInspector(ByVal inspector As inspector)
Dim objItem As Object
On Error GoTo 0
Set objInsp = inspector
Set objItem = objInsp.CurrentItem
Select Case objItem.Class
Case olMail
Set objMailItem = objItem
Case Else
End Select
End Sub
Private Sub objExpl_BeforeFolderSwitch(ByVal NewFolder As Object, Cancel As
Boolean)
On Error Resume Next
End Sub
Private Sub objExpl_Close()
Set objExpl = m_olApp.ActiveExplorer
If (objExpl Is Nothing) And _
(m_olApp.Inspectors.Count = 0) Then
UnInitHandler
End If
End Sub
Private Sub objInsp_Close()
If m_olApp.ActiveExplorer Is Nothing And _
m_olApp.Inspectors.Count <= 1 Then
UnInitHandler
End If
Set objInsp = Nothing
End Sub
Private Sub objMailItem_Close(Cancel As Boolean)
frmTest.Show 1 ' This is where Outlook hangs
End Sub
In Module modOutlook.bas
Option Explicit
Public m_olApp As Outlook.Application
In frmTest.frm with one button named brOK:
Private Sub btOk_Click()
Unload Me
End Sub