Solved

connection point sink implementation

Posted on 2002-04-14
4
666 Views
Last Modified: 2013-11-25
two part question so bear with me.  I'm trying to learn connection points and none of the books I've picked up have explained it very well imo.

I have an object with a dual interface callback in a dll.  I need to be able to implement this interface (sink?) in both an MFC application as well as a pure ATL COM exe.

my callback interface is "_CTEvents" and it has one callback method test(VARIANT nVal).

I need to know step by step how to go about implementing this callback in both the mfc client and the pure atl exe.  Including how I connect and disconnect the interface (advise?).  Please include as much example code as possible and walk me through this step by step.  Links to articles giving me further information on this subject would be helpful also.




0
Comment
Question by:Adept
4 Comments
 
LVL 1

Expert Comment

by:jemax
ID: 6941056
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 6941092
Hi,

  Try this link

  http://codeproject.com/useritems/connection.asp


GOOD LUCK
0
 
LVL 1

Accepted Solution

by:
pcj0961 earned 300 total points
ID: 6941705
there are few steps that need to be implemented to get the connection points setup

 the ATL project should be created with connection points so you should have a *CP.h
file with your connection point code in it.

template <class T>
class CProxy_IHVACEvents : public IConnectionPointImplMT<T, &DIID__IHVACEvents, CComDynamicUnkArray>
{
public:
      HRESULT Fire_HVAC_SystemEvent(ULONG dwParam1, ULONG dwParam2)
     {
      int nConnectionIndex;
       HRESULT ret;

       .
       .
       .
     
       return ret;
    }


now within your MFC *.h file you need to setup a sink interface

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;
 };


BEGIN_INTERFACE_PART(CHVAC_Events, IHVACEvents)
     STDMETHOD(HVAC_SystemEvent)(DWORD dwParam1, DWORD dwParam2);
END_INTERFACE_PART(CHVAC_Events)

in the .cpp file you need to create the interface

BEGIN_INTERFACE_MAP(CHVAC_UI, CPropertySheetEx)
     //INTERFACE_PART(CHVAC_UI, IID_IHVAC_UI, Dispatch) // not using dispatch interface
    INTERFACE_PART(CHVAC_UI, DIID__IHVACEvents, CHVAC_Events)
END_INTERFACE_MAP()

the  DIID__IHVACEvents is defined in the ATL object. normally I set my MFC project to look at the
ATL project directory to get access to  the  *_i.c file  but you can set this up as you like.

//////////////////////////////////////////////////////////////////////////////
// 3:IHVACEvents

IMPLEMENT_IUNKNOWN(CHVAC_UI, CHVAC_Events)

STDMETHODIMP CHVAC_UI::XCHVAC_Events::HVAC_SystemEvent(DWORD dwParam1, DWORD dwParam2)
{
    METHOD_PROLOGUE(CHVAC_UI, CHVAC_Events);

     g_pHVAC_UI->GetConfigurationMode();
    return NOERROR;
}

the last part is to make the connection.  make sure that the object has been already created using CreateInstance
before this.

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)
         {
          // set a flag that we have a connection point
          } // ppCP
     } // ppCPC
     }
} // QueryInterface

0
 

Author Comment

by:Adept
ID: 6965566
great, thats what i needed.
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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

747 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

12 Experts available now in Live!

Get 1:1 Help Now