add-in OnConnection trouble

  • Thread starter Thread starter Antonio Casilias
  • Start date Start date
A

Antonio Casilias

Hi,

I have outlook add-in (toolbar) that works properly when I launch main MS
Outlook application.
But if I launch Send To -> Mail Recipient from explorer's context menu I
take Debug assertion failed and my add-in crashes.

This is sample of OnConnection event handler code:

STDMETHODIMP CAddin::OnConnection(IDispatch * Application,
ext_ConnectMode ConnectMode,
IDispatch * AddInInst, SAFEARRAY * *
custom)
{

CComPtr < Office::_CommandBars> spCmdBars;
CComPtr < Office::CommandBar> spCmdBar;

// QI() for _Application
CComQIPtr spApp(Application);
ATLASSERT(spApp);
// get the CommandBars interface that represents Outlook's
//toolbars & menu items

CComPtr spExplorer;
spApp->ActiveExplorer(&spExplorer);

HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
if(FAILED(hr))
return hr;
ATLASSERT(spCmdBars);

//etc
<..>
}

The error occured on
HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);

Could you advice me how to determine if not main window has opened to avoid
this error?

Sorry, for my bad english.
Thanks in advance.
 
You can check the count of the Explorers collection before you try to do
anything else. If Outlook is started with no UI from Send To there is no
Explorer and you don't even get a NewInspector event.
 
Back
Top