Command repurposing using <command> construct in the Ribbon XML

J

JimTonra

I'm trying to use the command repurposing feature to grab control of the File
Print operation so I can decide based on the document content if the print
should be allowed.

I'm using the following XML in my GetCustomUI callback

....
<commands>
<command idMso="FilePrint" onAction="myPrint"/>
</Commands>
....

I'm using c++ (ATL) for the addin and have the following signature for my
onAction callback function:

idl:
[id(3), helpstring("method myPrint")] HRESULT myPrint([in] IDispatch*
RibbonControl, [out,retval] VARIANT_BOOL* pvarfCancelDefault);

c++
STDMETHODIMP CConnect::myPrint(IDispatch* RibbonControl, VARIANT_BOOL*
pvarfCancelDefault)


When I include this in my Ribbon XML, the File Print operation becomes a
no-op and my callback function is never called. Do I have the signature
wrong for this callback or is there something else I'm missing?
 
S

Sean Rohead

I have run into this exact same problem. My IDL is slightly different from
yours -- I have [in, out] on the second parameter (as shown in the FAQ at
http://msdn2.microsoft.com/en-us/library/aa722523.aspx), but other than that
it is the same.

I have turned on the 'Show add-in user interface errors' option, and I get a
message box stating: 'An error has occurred while calling the callback', but
no other information.

Advice on how to fix this would be greatly appreciated!
 
S

Sean Rohead

According to ribbon expert Eric Faller
(http://blogs.msdn.com/jensenh/archive/2006/12/08/using-ribbonx-with-c-and-atl.aspx),
the documentation is out of date and the correct method signature for the
callback is:

[id(5), helpstring("method BuiltInControlClicked")] HRESULT
BuiltInControlClicked([in] IDispatch* ribbonControl, [in,out] VARIANT*
cancel);

Note the second paramter is VARIANT* and not VARIANT_BOOL*.

Changing the method signature fixed my problem.

Sean Rohead said:
I have run into this exact same problem. My IDL is slightly different from
yours -- I have [in, out] on the second parameter (as shown in the FAQ at
http://msdn2.microsoft.com/en-us/library/aa722523.aspx), but other than that
it is the same.

I have turned on the 'Show add-in user interface errors' option, and I get a
message box stating: 'An error has occurred while calling the callback', but
no other information.

Advice on how to fix this would be greatly appreciated!

JimTonra said:
I'm trying to use the command repurposing feature to grab control of the File
Print operation so I can decide based on the document content if the print
should be allowed.

I'm using the following XML in my GetCustomUI callback

...
<commands>
<command idMso="FilePrint" onAction="myPrint"/>
</Commands>
...

I'm using c++ (ATL) for the addin and have the following signature for my
onAction callback function:

idl:
[id(3), helpstring("method myPrint")] HRESULT myPrint([in] IDispatch*
RibbonControl, [out,retval] VARIANT_BOOL* pvarfCancelDefault);

c++
STDMETHODIMP CConnect::myPrint(IDispatch* RibbonControl, VARIANT_BOOL*
pvarfCancelDefault)


When I include this in my Ribbon XML, the File Print operation becomes a
no-op and my callback function is never called. Do I have the signature
wrong for this callback or is there something else I'm missing?
 
J

JimTonra

Was that all you had to do? I changed my signature and fixed up the
implementation accordingly but still no go. My method is now getting called
but regardless of what I set the "cancel" variable to, the copy is always a
no-op.

Sean Rohead said:
According to ribbon expert Eric Faller
(http://blogs.msdn.com/jensenh/archive/2006/12/08/using-ribbonx-with-c-and-atl.aspx),
the documentation is out of date and the correct method signature for the
callback is:

[id(5), helpstring("method BuiltInControlClicked")] HRESULT
BuiltInControlClicked([in] IDispatch* ribbonControl, [in,out] VARIANT*
cancel);

Note the second paramter is VARIANT* and not VARIANT_BOOL*.

Changing the method signature fixed my problem.

Sean Rohead said:
I have run into this exact same problem. My IDL is slightly different from
yours -- I have [in, out] on the second parameter (as shown in the FAQ at
http://msdn2.microsoft.com/en-us/library/aa722523.aspx), but other than that
it is the same.

I have turned on the 'Show add-in user interface errors' option, and I get a
message box stating: 'An error has occurred while calling the callback', but
no other information.

Advice on how to fix this would be greatly appreciated!

JimTonra said:
I'm trying to use the command repurposing feature to grab control of the File
Print operation so I can decide based on the document content if the print
should be allowed.

I'm using the following XML in my GetCustomUI callback

...
<commands>
<command idMso="FilePrint" onAction="myPrint"/>
</Commands>
...

I'm using c++ (ATL) for the addin and have the following signature for my
onAction callback function:

idl:
[id(3), helpstring("method myPrint")] HRESULT myPrint([in] IDispatch*
RibbonControl, [out,retval] VARIANT_BOOL* pvarfCancelDefault);

c++
STDMETHODIMP CConnect::myPrint(IDispatch* RibbonControl, VARIANT_BOOL*
pvarfCancelDefault)


When I include this in my Ribbon XML, the File Print operation becomes a
no-op and my callback function is never called. Do I have the signature
wrong for this callback or is there something else I'm missing?
 
S

Sean Rohead

I was getting the no-op behaviour until I explicitly set the cancel variable
to false. Here's my callback:

STDMETHODIMP CConnect::BuiltInControlClicked(IDispatch* ribbonControl,
VARIANT* cancel)
{
*cancel = CComVariant(false);

return S_OK;
}


JimTonra said:
Was that all you had to do? I changed my signature and fixed up the
implementation accordingly but still no go. My method is now getting called
but regardless of what I set the "cancel" variable to, the copy is always a
no-op.

Sean Rohead said:
According to ribbon expert Eric Faller
(http://blogs.msdn.com/jensenh/archive/2006/12/08/using-ribbonx-with-c-and-atl.aspx),
the documentation is out of date and the correct method signature for the
callback is:

[id(5), helpstring("method BuiltInControlClicked")] HRESULT
BuiltInControlClicked([in] IDispatch* ribbonControl, [in,out] VARIANT*
cancel);

Note the second paramter is VARIANT* and not VARIANT_BOOL*.

Changing the method signature fixed my problem.

Sean Rohead said:
I have run into this exact same problem. My IDL is slightly different from
yours -- I have [in, out] on the second parameter (as shown in the FAQ at
http://msdn2.microsoft.com/en-us/library/aa722523.aspx), but other than that
it is the same.

I have turned on the 'Show add-in user interface errors' option, and I get a
message box stating: 'An error has occurred while calling the callback', but
no other information.

Advice on how to fix this would be greatly appreciated!

:

I'm trying to use the command repurposing feature to grab control of the File
Print operation so I can decide based on the document content if the print
should be allowed.

I'm using the following XML in my GetCustomUI callback

...
<commands>
<command idMso="FilePrint" onAction="myPrint"/>
</Commands>
...

I'm using c++ (ATL) for the addin and have the following signature for my
onAction callback function:

idl:
[id(3), helpstring("method myPrint")] HRESULT myPrint([in] IDispatch*
RibbonControl, [out,retval] VARIANT_BOOL* pvarfCancelDefault);

c++
STDMETHODIMP CConnect::myPrint(IDispatch* RibbonControl, VARIANT_BOOL*
pvarfCancelDefault)


When I include this in my Ribbon XML, the File Print operation becomes a
no-op and my callback function is never called. Do I have the signature
wrong for this callback or is there something else I'm missing?
 

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