Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Connection points - advise question

Posted on 2002-03-04
3
Medium Priority
?
277 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
ID: 6839177
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 150 total points
ID: 6839456
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
ID: 6841770
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

886 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