why GetCustomUI is not called (COM C++)

142 views
Skip to first unread message

Shang Yu

unread,
Apr 19, 2023, 12:08:55 AM4/19/23
to Excel-DNA
Hi guys,
I'm prototyping a COM(C++) addon for Excel, I implemented the IDTExtensibility2 and IRibbonExtensibility interface on my component. IDTExtensibility2 works fine but IRibbonExtensibility does not, that is, GetCustomUI never get called. 
I know this is the group for Excel-DNA. But I believe underlying mechanism is similar. So, any suggestion? Many thanks!

1585471449

unread,
Apr 19, 2023, 12:09:17 AM4/19/23
to Shang Yu
您的邮件已收到,谢谢!

Govert van Drimmelen

unread,
Apr 19, 2023, 4:46:36 AM4/19/23
to exce...@googlegroups.com
There's nothing unusual about the IRibbonExtensibilty COM interface or how Excel calls it, as far as I know. Depending on how you are implementing the COM interfaces in C++ you might need to add the interface to some ATL map or similar, and check that the interface GUID is right etc. I expect that Excel calls QueryInterface to get to it in the normal COM way.

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/a0c7a653-dc92-41c6-abaa-cc9f5094a041n%40googlegroups.com.

1585471449

unread,
Apr 19, 2023, 4:46:44 AM4/19/23
to Govert van Drimmelen
您的邮件已收到,谢谢!

Shang Yu

unread,
Apr 21, 2023, 2:48:26 AM4/21/23
to Excel-DNA
I can confirm that Excel has queried the IRibbonExtensibility interface and the querying is succeeded. It seems that Excel just query the interface and hold it for later use. So, I wonder if there are some prerequisites for calling GetCustomUI? Following is part of my ATL class for reference. Many thanks!
...
struct ATL_NO_VTABLE CAddon :
  CComObjectRoot,
  CComCoClass<CAddon,&CLSID_CAddon>,
  IRibbonExtensibility,
  ICustomTaskPaneConsumer,
  _IDTExtensibility2 {
  DECLARE_REGISTRY(CLSID_CAddon,"ebi.comaddon.1","ebi.comaddon","office",THREADFLAGS_BOTH);
  DECLARE_CLASSFACTORY();
  BEGIN_COM_MAP(CAddon)
    COM_INTERFACE_ENTRY(IRibbonExtensibility)
    COM_INTERFACE_ENTRY(ICustomTaskPaneConsumer)
    COM_INTERFACE_ENTRY(_IDTExtensibility2)
  END_COM_MAP();
...
};

Govert van Drimmelen

unread,
Apr 21, 2023, 3:16:08 AM4/21/23
to exce...@googlegroups.com
I'm pretty sure you need IDispatch support in there - inherit from IDispatchImpl too, add IDispatch to the interface map etc. The ribbon callbacks declared in the XML will be called via IDispatch, so Excel might be checking for that even before calling you GetCustomUI.

-Govert

Shang Yu

unread,
Apr 21, 2023, 6:56:07 AM4/21/23
to Excel-DNA
Thank you. It works roughly this way
...
struct ATL_NO_VTABLE CAddon :
  CComObjectRoot,
  CComCoClass<CAddon,&CLSID_CAddon>,
  IDispatch,

  IRibbonExtensibility,
  ICustomTaskPaneConsumer,
  _IDTExtensibility2 {
  DECLARE_REGISTRY(CLSID_CAddon,"ebi.comaddon.1","ebi.comaddon","office",THREADFLAGS_BOTH);
  DECLARE_CLASSFACTORY();
  BEGIN_COM_MAP(CAddon)
    COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IRibbonExtensibility)
    COM_INTERFACE_ENTRY(ICustomTaskPaneConsumer)
    COM_INTERFACE_ENTRY(_IDTExtensibility2)
  END_COM_MAP();
...
};

Govert van Drimmelen

unread,
Apr 21, 2023, 7:04:13 AM4/21/23
to exce...@googlegroups.com
Wonderful. You might need to inherit from IDispatchImpl and not just IDispatch for the callback implementations to get hooked up , but I'm not sure.

-Govert

Reply all
Reply to author
Forward
0 new messages