Help for a C++ menu handler in a COM add in?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm coding a com addin for outlook, in C++. My addin will have a menu on the
toolbar (a Office::CommandBarPopup that will have buttons added into its
CommandBarControls).

I'd prefer to "hook up" an event sink in a central location, like a C++
wrapper class, rather than needing to inherit from IDispEventSimpleImpl for
every single menu item. Couldn't I then distinguish between the events by
looking at a tag or menu caption?
 
Yes, you could use the Tag property (which must be set to a unique string
for each instance of a button), but why woudl you want to? Essentially you
will end up with a switch statement instead of a separate event handler
(function) for each button kind.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Sorry for the 2 similar posts: the site told me that "there was a problem
with the system" and the first "post was not received."

What does wrapper class mean in this context?

Can you point me at an example of a "wrapper class" for a "CComQIPtr
<Office::_CommandBarButton> pControl(pNewGuy);" the type that I can create N
instances of and DispEventAdvise at runtime without having inherited from
IDispEventSimpleImpl N times.

It appears that I need a separate "cookie" m_dwEventCookie for each call to
advise: is that from the IDispEventSimpleImpl, from the SINK_ENTRY_INFO, the
_ATL_FUNC_INFO instance, or what?

As for having only one callback, I would look up the appropriate action
(URL) based on the chosen menu caption. Kind-of like the Favorites
functionality, in that it is not predetermined.

I was able do this in MFC - am I nuts to attempt it in Outlook?
 
Again, I don't use C++ (I like Delphi better for this kind of stuff) - you
can create a class that implements the IDispatch interface (only
IDispatch::Invoke() needs to be implemented). When you create a new button,
create an instance of the wrapper class, jump through the usual hoops to
get to the IConnectionPoint interface, call Advise passing that new instance
of the wrapper class. Whenever the click event occurs, your implementation
of the IDispatch::Invoke() will be called with the appropriate dispid.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top