Solved

Connection points - advise question

Posted on 2002-03-04
3
240 Views
Last Modified: 2013-11-20
Hi,

I want to make advise for a connection point in my MFC application.
I need an IUnknown pointer of the sink, to pass it as an argument for 'advise' method.

My question is, how to get this pointer ?

Thanks
Michael
0
Comment
Question by:MichaelMaromm
3 Comments
 
LVL 5

Expert Comment

by:ekc
Comment Utility
The sink interface belongs to a client side of the event-mechanism, to an object you need to create and manage in your client code.
Tipicaly, you will create an object on the client side which will implement the same interface as the one in the connection point object you want to connect to. Then you will create the instance of this object (now you have the pointer), and pass its IUnknown to Advise function...
0
 
LVL 1

Accepted Solution

by:
pcj0961 earned 50 total points
Comment Utility
I have recently implemented a connection point from an ATL object to an MFC application and this is how I did it.

in the *.h MFC file

class IHVACEvents : public IUnknown
{
public:
    // Standard IUnknown interface functions
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID* ppvObj) = 0;
    virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0;
    virtual ULONG STDMETHODCALLTYPE Release(void) = 0;

    // This interface
    virtual HRESULT STDMETHODCALLTYPE HVAC_SystemEvent(DWORD dwParam1, DWORD dwParam2) = 0;
    virtual HRESULT STDMETHODCALLTYPE HVAC_SystemInterfaceEvent(DWORD dwParam1, DWORD dwParam2) = 0;
};

    // Declare the interface map for this object
    DECLARE_INTERFACE_MAP()

   // IHVACEvents interface
    BEGIN_INTERFACE_PART(HVACEvents, IHVACEvents)
        STDMETHOD(HVAC_SystemEvent)(DWORD Event, DWORD Address);
        STDMETHOD(HVAC_SystemInterfaceEvent)(DWORD Event, DWORD Address);
   END_INTERFACE_PART(HVACEvents)

end of *.h file

in the *.cpp MFC file

 //DIID__IHVACEvents is an IID of the connection point interface (ATL source)  and  is declared in the following included file
#include "Enerzone_i.c"

BEGIN_INTERFACE_MAP(CMainFrame, CFrameWnd)
    INTERFACE_PART(CMainFrame, DIID__IHVACEvents, HVACEvents)
END_INTERFACE_MAP()


/* this code connects the sink and source */

// query for the sink (MFC) IUnknown (below)
  if(ExternalQueryInterface( &DIID__IHVACEvents, (void**) &m_pIHVACEvents ) == S_OK)
  {
    // get interface pointer to the connection point container
   if(m_pHVAC->QueryInterface( IID_IConnectionPointContainer, (void**) &ppCPC ) == S_OK)
    {
      // if the interface exists then setup a connection point
         if(ppCPC->FindConnectionPoint( DIID__IHVACEvents,  (IConnectionPoint**) &m_pHVAC_CP ) == S_OK)
          {
            // tie to connection point
            if(m_pHVAC_CP->Advise( m_pIHVACEvents, &HVAC_Cookie ) == S_OK)
            {
            }
          }
      }
  }


/* this is the actual sink interface */

IMPLEMENT_IUNKNOWN(CMainFrame, HVACEvents)

STDMETHODIMP CMainFrame::XHVACEvents::HVAC_SystemEvent(DWORD dwParam1, DWORD dwParam2)
{
    METHOD_PROLOGUE(CMainFrame, HVACEvents);

    return NOERROR;
}

STDMETHODIMP CMainFrame::XHVACEvents::HVAC_SystemInterfaceEvent(DWORD Event, DWORD NumEvents)
{
    METHOD_PROLOGUE(CMainFrame, HVACEvents);

    return NOERROR;
}

end of *.cpp file
0
 

Author Comment

by:MichaelMaromm
Comment Utility
Hi pcj0961,

Thanks for your answer,

The compiler want the IDispatch implementation at the interface map :

BEGIN_INTERFACE_MAP(CMainFrame, CFrameWnd)
   INTERFACE_PART(CMainFrame, DIID__IHVACEvents, HVACEvents)
END_INTERFACE_MAP()


How can I add the IDispatch implementation to my MFC sink ?

Thanks
Michael.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now