InvalidateRibbon failing with Object Required return code

M

mwiles

I am updating my COM project to use the ribbon instead of the commandbar for
Office 2007. I used to have the behavior that I can enable / disable
buttons as needed. I have read about Invalidate & InvalideControl for the
RibbonControl but am getting undesired results when executing the following
test code. I have copied snippits of code from my project ...

LPDISPATCH m_pRibbonUI;

STDMETHODIMP MyRibbon::OnLoad(LPDISPATCH pRibbonUI)
{
// store a reference to the parm to invalidate the UI
// in certain cases buttons may need to be disabled and
// invalidating will refresh the ribbon
m_pRibbonUI = pRibbonUI;
if( m_pRibbonUI )
m_pRibbonUI->AddRef();
return S_OK;
}

void MyRibbon::ButtonClick()
{
InvalidateRibbon();
}

void MyRibbon::InvalidateRibbon()
{
if( m_pRibbonUI )
{
HRESULT hr;
VARIANT vtRtn; VariantInit(&vtRtn);
DISPID dwDispID;
DISPPARAMS dispparams = {NULL, NULL, 0, 0};
dispparams.rgvarg = NULL;
dispparams.cArgs = 0;
EXCEPINFO eInfo;
UINT uInt;
hr = m_pRibbonUI->GetIDsOfNames(IID_NULL, "Invalidate", 1,
LOCALE_USER_DEFAULT, &dwDispID);
if ( SUCCEEDED(hr) )
hr = m_pRibbonUI->Invoke(dwDispID, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &dispparams, &vtRtn, &eInfo, &uInt);
}
}

I am able to get the correct ID for the methods Invalide (1) InvalideControl
(2) ... but when I call either of them, Invalidate with no parms, Invalidate
with one VT_BSTR parm of the ControlID in the RibbonXML, I get the following
returncode dec:-2146827864

Any help would be greatly appreciated... I am at a loss.
 
K

Ken Slovak - [MVP - Outlook]

I don't do C++ so I can't help with the exact syntax, but in general when
you call Invalidate() or InvalidateControl(idMSO) you force the callbacks
you've set up in your XML to fire. For example, if you have a getVisible()
callback and you call Invalidate() that will fire the callback for each of
your ribbon controls. The same applies for a getEnabled() callback, etc.

This link may help:
http://blogs.msdn.com/jensenh/archive/2006/12/08/using-ribbonx-with-c-and-atl.aspx
 
M

mwiles

Ken,

Thanks for the link, I think I found that when surfing for help .. but I
will re-read.

While I did not post my complete solution, I do have callbacks set up and
they get called when I open a document and focus gets put on the Home Ribbon
Tab .. when I switch to my Tab, my callbacks are called, but when I try to
call Invalidate (after clicking one of my buttons to reset button states) on
the Ribbon interface, I get an error ... and therefore my callbacks are not
called. It seems odd that the interface is acknowledging the signature for
"Invalidate" but its returning an error.

-Mike
 

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