Solved

Connection points - advise question

Posted on 2002-03-04
3
247 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 50 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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