Solved

Connection points - advise question

Posted on 2002-03-04
3
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

627 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