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

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.
 
R

Randy Byrne [MVP - Outlook]

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
 
M

Mark Ingram

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.
 

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