locked
Getting events from a COM object RRS feed

  • Question

  • Hello:

    I don´t know if this question belongs or not to this thread, but if you consider that there´s a suitable thread for it, please, let me know.

    About my question: I´m trying to get the events of a COM event source object and a part of this task is implementing the dispinterface handling those events through inheriting the ATL class IDispEventImpl. Later on my code I call to DispEventAdvise in order to connect the outgoing interface of the connectable object (the event source object) with the proper connection point. Everything compiles fine and such a call succeeds, however, the application exits each time it gets an event, so that makes me think that I did something wrong in relation with the event handling mechanism.

    Here there is the sink object implementation:

    static _ATL_FUNC_INFO _funcOnText = {
      CC_STDCALL,             // Calling convention.
      VT_I4,                         // Return type.
      1,                                 // Number of arguments.
      {                                  // Argument types.
        VT_BSTR
      }
    };


    class SrmPseudoDocumentEvents : public IDispEventImpl<1,
           SrmPseudoDocumentEvents,
           &__uuidof(SmIa::PseudoDocumentEvents),
           &GUID_NULL, 1, 0>
    {

    public:

      SrmPseudoDocumentEvents() {
       
      };
     
      virtual ~SrmPseudoDocumentEvents() {
       
      };
     
      STDMETHODIMP OnText(BSTR a_recognizedText) {
        KlDebugAlways("Text event !!!");
        return S_OK;
      };

      BEGIN_SINK_MAP(SrmPseudoDocumentEvents)
        SINK_ENTRY_INFO(1, __uuidof(SmIa::PseudoDocumentEvents), 0x01, OnText, &_funcOnText)
      END_SINK_MAP()

    };


    And here I call the DispEventAdvise method call:

    SrmPseudoDocumentEvents pseudoDocumentEvents = SrmPseudoDocumentEvents();

      hr = pseudoDocumentEvents.DispEventAdvise(reinterpret_cast<IUnknown*>(m_pIPseudoDocument),
                                                &__uuidof(SmIa::PseudoDocumentEvents));
      if (FAILED(hr)) {
        return getHResultInfo(hr,
                              reinterpret_cast<IDispatch*>(&pseudoDocumentEvents),
                              __uuidof(SmIa::PseudoDocumentEvents));
      }



    Thank you beforehand,

    Marcos
    • Edited by Markkos Wednesday, November 12, 2008 10:33 AM
    Wednesday, November 12, 2008 10:33 AM

Answers

All replies