PC Review


Reply
Thread Tools Rate Thread

destroying Explorer object pointers on shutdown

 
 
Gabriel
Guest
Posts: n/a
 
      23rd Apr 2009
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:ispEventUnadvise((IDispatch*)m_spExplorer);

spExplorerEvents2:ispEventUnadvise((IDispatch*)m_spExplorer);

spExplorerEvents3:ispEventUnadvise((IDispatch*)m_spExplorer);

m_spExplorer = NULL;

}


}

As always, any assistance is greatly appreciated.

-Gabriel
 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      24th Apr 2009
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" <(E-Mail Removed)> wrote in message
news:EE559A29-9E33-41AE-8CC9-(E-Mail Removed)...
> 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:ispEventUnadvise((IDispatch*)m_spExplorer);
>
> spExplorerEvents2:ispEventUnadvise((IDispatch*)m_spExplorer);
>
> spExplorerEvents3:ispEventUnadvise((IDispatch*)m_spExplorer);
>
> m_spExplorer = NULL;
>
> }
>
>
> }
>
> As always, any assistance is greatly appreciated.
>
> -Gabriel


 
Reply With Quote
 
Gabriel
Guest
Posts: n/a
 
      4th May 2009
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
COM object import and pointers Trevor Microsoft Dot NET Compact Framework 0 19th May 2009 08:22 PM
object pointers rando4 Microsoft Excel Programming 2 25th Oct 2005 04:04 AM
Deterministically destroying a COM object Robert Rotstein Microsoft C# .NET 1 18th Sep 2005 08:38 PM
What is the correct way of destroying an object who is listening to delegate events? Darren Microsoft C# .NET 1 6th Sep 2004 04:56 PM
Object destroying problem... Roman S. Golubin1709176985 Microsoft C# .NET 1 12th Sep 2003 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:34 AM.