Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 716
  • Last Modified:

connection point sink implementation

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
Adept
Asked:
Adept
1 Solution
 
jemaxCommented:
0
 
Roshan DavisCommented:
Hi,

  Try this link

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


GOOD LUCK
0
 
pcj0961Commented:
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
 
AdeptAuthor Commented:
great, thats what i needed.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now