Outlook.exe not disappearing, but only in a very specific case

C

Chris Bardon

OK, this one's a little weird, so bear with me. I have an application
that uses a regular COM server that's accessed from multiple client
applications. It loads a singleton exe server, other applications
connect to it, and once the last client application exits, the COM
sever is destroyed. Simple so far.

Now, one of the services this COM server provides is the ability to
interface with Outlook contacts. I've done this using some managed C+
+ code, and basically done this to access the contacts:

m_OutlookApp = gcnew
Microsoft::Office::Interop::Outlook::Application();
m_MapiNamespace = m_OutlookApp->GetNamespace("mapi");
m_MapiFolder = m_MapiNamespace-
GetDefaultFolder(Microsoft::Office::Interop::Outlook::OlDefaultFolders::eek:lFolderContacts);

And then this to release everything:

System::Runtime::InteropServices::Marshal::ReleaseComObject(m_OutlookApp);
m_OutlookApp=nullptr;
m_MapiNamespace=nullptr;
m_MapiFolder=nullptr;
GC::WaitForPendingFinalizers();
GC::Collect();

Again, if I have a regular application load my COM server, I see the
COM server create an instance of Outlook.exe, use it, and then when
the COM server exits, Outlook exits.

Now comes the fun part. One of the client applications that can
reference this COM object just happens to be an Outlook addin. This
means that when the COM server is loaded, it creates a reference to
Outlook.exe, which in turn creates a reference to my COM server by
loading the addin. This all works just as expected, except when I go
to shut down. When I close Outlook, the reference to the COM server
is released, and FinalRelease() is called, so I clean up the Outlook
COM object with the above code. The problem is, Outlook.exe is still
kicking around afterwards, and I can't figure out why. It's a case
where both parts work in isolation: If I remove the Outlook contact
COM stuff from the COM server and load my addin Outlook.exe closes,
and if I have just the contact stuff enabled but the addin disabled
outlook.exe closes, but not both.

Any suggestions on debugging this one? I've checked out
http://support.microsoft.com/?kbid=317109, and I tried calling
m_OutlookApp->Quit();, but that gives me Error 1 error C2385 which is
"ambiguous access of 'Quit'".

Thanks for the help,

Chris
 

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