Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Add-ins for Outlook (http://www.outlookbanter.com/add-ins-outlook/)
-   -   destroying Explorer object pointers on shutdown (http://www.outlookbanter.com/add-ins-outlook/89445-destroying-explorer-object-pointers-shutdown.html)

Gabriel April 23rd 09 09:47 PM

destroying Explorer object pointers on shutdown
 
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

Ken Slovak - [MVP - Outlook] April 24th 09 02:22 PM

destroying Explorer object pointers on shutdown
 
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Gabriel" wrote in message
...
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



Gabriel May 4th 09 08:57 PM

destroying Explorer object pointers on shutdown
 
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

"Ken Slovak - [MVP - Outlook]" wrote:

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm




All times are GMT +1. The time now is 10:20 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com