com add-in and newexplorer event

J

JL

Hi,

I'm writing a COM add-in for Outlook in Visual C++/ATL.
In my add-in I use among other things the OnFolderSwitch event of the
dispinterface ExplorerEvents and OnUpdate event of the dispinterface
_CommandBars
in order to add items to the main menu and the context menu of
outlook.
My add-in works perfectly but only for the first "instance" of Outlook
(the window that's opened when Outlook opens). My goal is that it
works for each new explorer window. For that I use the OnNewExplorers
event to get the new explorer and connect it to the OnfolderSwitch,
OnClose, etc... events with DispEventAdvise(). Before I have naturally
to disconnect the "old" explorer from these events (if I don't
disconnect it the add-in crashes):

void __stdcall CSMSAddin::OnNewExplorers(IDispatch* pDisp)
{
CComQIPtr<Outlook::_Explorer> spNewExplorer(pDisp);
ATLASSERT(spNewExplorer);
pDisp->Release();

HRESULT hr;

// Unadvise to stop notification of OnFolderSwitch,
OnSelectionChange, OnActivate, OnDeactivate, OnClose events for the
"old" explorer.
hr = ExpEvents::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents3::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents4::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents5::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents6::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);

m_spExplorer = spNewExplorer;

// Advise for the OnFolderSwitch, OnSelectionChange, OnActivate,
OnDeactivate, OnClose events for the new explorer.
hr = ExpEvents::DispEventAdvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents3::DispEventAdvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents4::DispEventAdvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents5::DispEventAdvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents6::DispEventAdvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
}

Then I disconnect the explorer in the OnClose event.

void __stdcall CSMSAddin::OnExplorerClose()
{
HRESULT hr = ExpEvents::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents3::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents4::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents5::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
hr = ExpEvents6::DispEventUnadvise((IDispatch*)m_spExplorer);
ATLASSERT(hr == S_OK);
MessageBox(NULL,"close", "outlook",MB_OK);
}


That's work !....but if I close the new explorer and go back to the
"old" window my add-in don't work anymore :(
It's logical since my "old" explorer is now disconnected... I
understand the problem but I don't see the solution.
How to connect again the "old" explorer to the events ?
Is there another way to solve this problem ?
In my searches I've seen the ItemsCB COM add-in example
(www.microeye.com) but it's in VB and I'm programming in C++...
I try to find a solution for a week. Please help me !

Thank you very much
Robert
 
S

sandy91

Hi, I'm working on a similar problem, and I would like to see that response.
But I can't find a followup from the same day in the other Outlook "Community
Newsgroups" - not "Developer Forms" and not "Programming".

Dmitry, where did you put your reply?

thanks
Sandy
 

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