Event handler for menu item

C

Cameron

I am developing a Add-in for MS Word that add's several menu items to
the sub menus of the main menu as well as some toolbar buttons. All
is working except that if I try to sink the events for the menu items
in the same way as for the toolbar buttons I get an access violation
when i call QueryInterface in the code

void CButtonHandler::SinkEvents(LPDISPATCH pButton)
{
HRESULT hr;

// Get server's IConnectionPointContainer interface.
IConnectionPointContainer* pCPC;
hr = pButton->QueryInterface(IID_IConnectionPointContainer, (void
**)&pCPC);
if (SUCCEEDED(hr)) {

// Find connection point for events we're interested in.
hr = pCPC->FindConnectionPoint(DIID__CommandBarButtonEvents,
&m_pConnection);
if (SUCCEEDED(hr)) {
m_pConnection->Advise(static_cast<IDispatch*>(this),
&m_dwCookie);
}
// Release the IConnectionPointContainer
pCPC->Release();
}
}

This problem only occurs when the LPDISPATCH is that of a menu item
control.

Can anyone advise me on how I can add event handlers for menu items.
Also how does one update items so they are enabled/disabled as
appropriate (i.e. based on document contents/selection etc.)


Many thanks in advance

Cam Banks
 

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