destroying Explorer object pointers on shutdown

G

Gabriel

Another newbie question here. I'm writing an ATL/COM add-in for Outlook 2003.
When quitting Outlook, I was getting an "abnormal program termination" error.
If I understand correctly, this is probably a result of not releasing my
Explorer object pointer? I added a sink for the explorer close event as
recommended but I guess I have to do something other than just set my pointer
to NULL?

(My pointer is: CComPtr <Outlook::_Explorer> m_spExplorer;)


Here's my code (checking to see if this is the last :




// gives an "assertion failed" error
void _stdcall CAddin::OnExplorerClose(){

CComPtr <Outlook::_Explorers> spExplorers;

m_spApp->get_Explorers(&spExplorers);

long count;

spExplorers->get_Count(&count);

if (count == 1){

spExplorerEvents::DispEventUnadvise((IDispatch*)m_spExplorer);

spExplorerEvents2::DispEventUnadvise((IDispatch*)m_spExplorer);

spExplorerEvents3::DispEventUnadvise((IDispatch*)m_spExplorer);

m_spExplorer = NULL;

}


}

As always, any assistance is greatly appreciated.

-Gabriel
 
K

Ken Slovak - [MVP - Outlook]

The algorithm is to check in the Close() event for that being the final
Explorer and no Inspectors. Then you have to release all your Outlook object
pointers, not just Explorers. If you have handles to Application, NameSpace,
etc. they all must be released.
 
G

Gabriel

Hi Ken,

Thanks for the input. Turns out I'd erroneously added
"m_spExplorer->Close()" to the OnBeginShutdown method when I was first
troubleshooting so I didn't notice one error being replaced by another
similar one (since of course by the time it was called I'd already released
it). Guess it pays to actually read those assertions!

Thanks again,

-Gabriel
 

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