Solved

connection point sink implementation

Posted on 2002-04-14
4
672 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
either24  challenge 19 97
Unix Command -- Challenging  question 7 92
Need more details 5 153
Licensing Sharepoint 2016 for developers 11 47
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.
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…

803 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