Solved

Connection points - advise question

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…

752 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