add-in OnConnection trouble

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.
 
K

Ken Slovak - [MVP - Outlook]

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.
 

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