[C#] OL2000: You Cannot Fully Quit Outlook When You Use a COM Add-in

  • Thread starter Thread starter Mark Ingram
  • Start date Start date
M

Mark Ingram

Hi,

has anyone managed to get around this problem of not
being able to close Outlook fully with C#?

In the MS article they list some code, but its VB code:

Public WithEvents oMyExplorer As Outlook.Explorer

Sub oMyExplorer_Close()
' Release the Explorer object
Set oMyExplorer = Nothing
End Sub


How can i "Implement the Close event for the Explorer or
Inspector object, and then set the corresponding object
variable to Nothing at the end of that event. " with C#??

Thanks alot.
 
The Close event should call UnInitHandler, which releases object references.
Don't set m_olExplorer==null in the OnExplorerClose procedure. Here is
sample code for OnExplorerClose, which is the event handler for
m_olExplorer.

In your InitHandler():

//Instantiate Explorer and hookup associated events

m_olExplorer = (Outlook.ExplorerClass)m_olApp.ActiveExplorer();

m_olExplorer.ExplorerEvents_Event_Close +=

new Outlook.ExplorerEvents_CloseEventHandler(this.OnExplorerClose);

//This procedure handles the Close event.

private void OnExplorerClose()
{
Debug.WriteLine("--- OnExplorerClose Called ---");
try
{
m_olExplorer = (Outlook.ExplorerClass)m_olApp.ActiveExplorer();
if ((m_olExplorer == null)
&& (m_olInspectors.Count == 0))
{
UnInitHandler();
}
}
catch (SystemException ex)
{
Debug.WriteLine(String.Format(
"OnExplorerClose Exception: {0}", ex.Message));
}
}

--
Randy Byrne, MVP - Outlook
http://www.microeye.com
Building Applications with Microsoft Outlook 2002 (MSPress - July 2001)
Building Applications with Microsoft Outlook 2000 (MSPress)
http://www.microeye.com/books
Micro Eye ZipOut
http://www.microeye.com/zipout
 
Hi Randy,

thanks for your fast reply. I tried making changes as you
suggested but unfortunately it wont recognise the
class "Outlook". What is the system reference i need?

Alternatively do you have some small example code (just
loading and unloading of the COM object) i could look at?

Cheers

Mark Ingram.
 
Back
Top