Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Interesting COM ATL Event question.

Interesting COM ATL Event question.

Scheduled Pinned Locked Moved ATL / WTL / STL
questionc++wpfcomhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brigsoft
    wrote on last edited by
    #1

    There are some ATL templates and macros that help catch COM events. As IDispEventSimpleImpl, SINK_ENTRY_INFO etc. But what I must to do if I do not know all events before a program start. For example, there are Outlook::ItemsEvent for Outlook folders. I can catch any one. But I want catch all to one function. How can I register events dynamically? Your ideas? ================================ My home is here!

    J 1 Reply Last reply
    0
    • B Brigsoft

      There are some ATL templates and macros that help catch COM events. As IDispEventSimpleImpl, SINK_ENTRY_INFO etc. But what I must to do if I do not know all events before a program start. For example, there are Outlook::ItemsEvent for Outlook folders. I can catch any one. But I want catch all to one function. How can I register events dynamically? Your ideas? ================================ My home is here!

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      Brigsoft wrote: But what I must to do if I do not know all events before a program start. Then you're in for a rough ride. COM events are either tied to a vtable entry (non-dispinterface source) or to a DISPID (dispinterace source). In both cases, the events are tied to an interface ID. You must know in advance what you're dealing with. Of course, one could devise a more dynamic homebrew event scheme - but alas, that's not the case here. COM events are as static as stone. Brigsoft wrote: But I want catch all to one function. You can do this quite easily if the source interface is a dispinterface. Simply implement the dispinterface "manually" in a separate class like this:

      template <typename T, typename SourceInterface, int ID>
      class CSourceInterfaceImpl {
      public:
      HRESULT Init() {
      // Create type info stuff, preferably using CreateDispTypeInfo()
      // based on the interface passed as template parameter. Feel
      // free to use __uuidof(SourceInterface) if portability is of no
      // concern
      ...
      }

      void Finalize() {
      // Release type info
      }

      // Important. Do NOT implement the IUnknown part here. These
      // methods must be implemented by the COM class so that we don't
      // break any COM rules.
      STDMETHOD(GetIDsOfNames)(...) {
      // Implement this, preferably using DispGetIDsOfNames()
      }

      STDMETHOD(GetTypeInfo)(...) {
      // pass back the type info object created in constructor
      }

      STDMETHOD(GetTypeInfoCount)(...) {
      // Return 1
      }

      STDMETHOD(Invoke)(...) {
      // this is where we dispatch the calls to "the one and only"
      // function.
      return static_cast<T>(this)->EventInvocation(
      ID,
      ... // The rest of the parameters passed to this function
      );
      }
      };

      #define ID_FOR_EVENTS_X 1
      #define ID_FOR_EVENTS_Y 2
      #define ID_FOR_EVENTS_Z 3

      class ATL_NO_VTABLE CMyCOMClass :
      public ..., // boiler plate ATL code
      // This is where we reuse the CSourceInterfaceImpl template
      public CSourceInterfaceImpl<CMyCOMClass, ISourceX, ID_FOR_EVENTS_X>,
      public CSourceInterfaceImpl<CMyCOMClass, ISourceY, ID_FOR_EVENTS_Y>,
      public CSourceInterfaceImpl<CMyCOMClass, ISourceZ, ID_FOR_EVENTS_Z>
      {
      ... // ATL boiler plate code
      HRESULT FinalConstruct() {
      HRESULT hr; // handling of errors omitted for brevity
      hr = CSourceInterfaceImpl<CMyCOMClass, ISo

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups