This is my Visual C++ wrapper that initialises own DLL library:
void COutlookManagerEx::Init()
{
throw_if_fail(m_pInterface.CreateInstance(__uuidof(PTSOutlookLibrary::PTSOutlookLibraryClass)));
if (IsValid())
m_pInterface->ShowMicrosoftOutlook();
}
The C# constructor:
public PTSOutlookLibraryClass()
{
try
{
_OutlookApp = new Outlook.Application();
}
catch(Exception /* e */)
{
}
}
The C# method to display Outlook:
public void ShowMicrosoftOutlook()
{
// Show Outlook
if (_OutlookApp.Explorers.Count == 0)
{
Outlook.MAPIFolder oFolder = _OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
oFolder.Display();
}
}
My COutlookManagerEx
is a member variable of a CDialog
:
private:
COutlookManagerEx m_OutlookManager;
For some reason, when I close my CDialog
object Microsoft Outlook stays open.
Update
Based on similar questions I have tried:
public void Terminate()
{
try
{
Marshal.ReleaseComObject(_OutlookApp);
}
catch
{
}
finally
{
_OutlookApp = null;
}
}
And adding my own wrapper and then calling Terminate
when my dialog closes but Outlook is still visible.