Question

I have a class that inherits from "DispEventAdvise" (for outlook2010, but its not important):

class item_2010_event_handler : 
public IDispEventSimpleImpl<IDC_OUTLOOK_ITEM_2010_EVENTS, 
                            item_2010_event_handler, 
                            &outlook_item_2010_ev_id>

Now, I want to register a single instance of item_2010_event_handler to get events from multiple objects, so I call DispEventAdvise() multiple times (once for each object), but from the 2nd time I call DispEventAdvise() I get "Unknown Error" exception from the function.

Is it possible it is not supported? and if not, why not???

If it is possible, what am I missing (obviously I'll add more code if it is needed...)?

Was it helpful?

Solution

Each "copy" of IDispEventSimpleImpl you inherit from keeps a so called "cookie", a value you provide back to the connection point later when you need to unadvise/disconnect from events. Having said that, IDispEventSimpleImpl class (note word "simple" in the name) supports only one connection.

Your choices are:

  1. rewrite IDispEventSimpleImpl class so that replacement class could connect to multiple points properly managing the connections
  2. create one helper instance of connection point sink class per connection, then forward calls back to the owner making it gather calls from multiple sources - recommended
  3. inherit several times from different IDispEventSimpleImpl bases to support more (fixed amount though - lacks flexibility, good for several connections one per source type) connections on a single instance
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top