Repurpose and Office 2007 Button Callback Signature

M

Mark Wilson

I'm trying to repiurpose an Office 2007 button on an Outlook Inspector.

The Addin is Native C++ using ATL. When the button is clicked I get the
following error:

Custom UI Runtime Error in Sample Addin
Callback signature mismatch: “OnClickâ€

The IDL defines the function as follows:

[id(43),helpstring("method OnClick")]
HRESULT OnClick([in] IDispatch* RibbonControl, [out,retval] VARIANT*
CancelDefault);

I've also tried defining the return value as VARIANT_BOOL* CancelDefault
without any success. (That's what the documentation said to use
http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx)

Since the error doesn't tell me what Outlook is expecting, how do I debug
this?
 
M

Mark Wilson

Thanks Ken.

I had already looked at that and I have standard button clicks working fine.

My problam is Ribbon specific. I based my code on this sample
http://msdn.microsoft.com/en-us/lib...dingNativeAddinforOL2010_CreatingaNativeAddin

I can intercept the click event of a "new" button added to the Ribbon. It
seems that Outlook doesn't like something about my repurpose Callback method
and exactly what is probably obscured somewhere in ATL.


--
Mark Wilson



Ken Slovak - said:
I'm no C++ programmer so I can't specifically help with that, but see if the
approach for handling a button click (in this case for a context menu click)
at http://www.codeproject.com/kb/atl/outlook2k3addin.aspx helps you at all.
That part of the code is towards the bottom of the article.




Mark Wilson said:
I'm trying to repiurpose an Office 2007 button on an Outlook Inspector.

The Addin is Native C++ using ATL. When the button is clicked I get the
following error:

Custom UI Runtime Error in Sample Addin
Callback signature mismatch: “OnClickâ€

The IDL defines the function as follows:

[id(43),helpstring("method OnClick")]
HRESULT OnClick([in] IDispatch* RibbonControl, [out,retval] VARIANT*
CancelDefault);

I've also tried defining the return value as VARIANT_BOOL* CancelDefault
without any success. (That's what the documentation said to use
http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx)

Since the error doesn't tell me what Outlook is expecting, how do I debug
this?

.
 
M

Mark Wilson

Hi Ken.

I had tried that earlier. The Blog doesn't go into detail on repurposing
Ribbon controls. I'm having the same issue as Sean Rohead in the Blog
comments. I've tried both VARIANT* and VARIANT_BOOL*. While he was able to
solve his issue, mine is still broken.

Three years later the dicumentation on callback signatures still hasn't been
corrected. When Microsoft joins this thread, I'll ask then to have the web
documentation updated.
 
K

Ken Slovak - [MVP - Outlook]

In case they don't look at this thread because I answered in it, I'd
recommend starting a new thread. Mention you've looked at both of those
references you provided already so you don't have go over the same ground.
I'll stay out of that thread so the MS support engineers will enter the
thread.

Sorry I couldn't help you with the problem.
 
J

Ji Zhou

Sorry for updating late. Our tool stops working so my reply was not
synchronized. Post as follows,

The problem is fixed if we change the callback function declaration as the
following,

NativeAddin.idl,

interface IRibbonCallback : IDispatch{
[id(42),helpstring("Button Callback")] HRESULT
ButtonClicked([in]IDispatch* ribbonControl);
[id(43),helpstring("method OnPrintClick")] HRESULT OnPrintClick([in]
IDispatch* RibbonControl, [in,out] VARIANT* CancelDefault);
};

Connect.h,
STDMETHODIMP CConnect::OnPrintClick(IDispatch* RibbonControl, VARIANT*
CancelDefault)
{
if (MessageBoxW(NULL,L"Print this message?",
L"CClassifyAddin::OnPrintClick", MB_ICONQUESTION | MB_YESNO) == IDYES)
{
CancelDefault->boolVal = VARIANT_FALSE;
}
else
{
CancelDefault->boolVal = VARIANT_TRUE;
}
return S_OK;
}

The point is that we need to use [in, out] instead of [retval]. [retval] is
for functions that we need to get a return value, for example, the GetLabel
callback. And another thing is that we need to use VARIANT instead of
VARIANT_BOOL. The documentation has something wrong. I will add a comment on
the document and try to contact the content team to fix this.


Best regards,
Ji Zhou - MSFT
Microsoft Online Community Support
 
M

Mark Wilson

Thanks Ji.

Replacing [out,retval] with [in,out] in the IDL file fixed the problem.
--
Mark Wilson



Ji Zhou said:
Sorry for updating late. Our tool stops working so my reply was not
synchronized. Post as follows,

The problem is fixed if we change the callback function declaration as the
following,

NativeAddin.idl,

interface IRibbonCallback : IDispatch{
[id(42),helpstring("Button Callback")] HRESULT
ButtonClicked([in]IDispatch* ribbonControl);
[id(43),helpstring("method OnPrintClick")] HRESULT OnPrintClick([in]
IDispatch* RibbonControl, [in,out] VARIANT* CancelDefault);
};

Connect.h,
STDMETHODIMP CConnect::OnPrintClick(IDispatch* RibbonControl, VARIANT*
CancelDefault)
{
if (MessageBoxW(NULL,L"Print this message?",
L"CClassifyAddin::OnPrintClick", MB_ICONQUESTION | MB_YESNO) == IDYES)
{
CancelDefault->boolVal = VARIANT_FALSE;
}
else
{
CancelDefault->boolVal = VARIANT_TRUE;
}
return S_OK;
}

The point is that we need to use [in, out] instead of [retval]. [retval] is
for functions that we need to get a return value, for example, the GetLabel
callback. And another thing is that we need to use VARIANT instead of
VARIANT_BOOL. The documentation has something wrong. I will add a comment on
the document and try to contact the content team to fix this.


Best regards,
Ji Zhou - MSFT
Microsoft Online Community Support

Mark Wilson said:
Thanks Ken.

I've already been contacted by Ji Zhou at Microsoft on this issue.
 

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