Article ID: 181845
Article Last Modified on 10/21/2005
BEGIN_DISPATCH_MAP(CMySink, CCmdTarget)
DISP_FUNCTION_ID(CMySink,"Quit",2,OnObjQuit,VT_EMPTY,VTS_I4 VTS_I4)
END_DISPATCH_MAP()
The code above is an entry for handling the Quit event with a DISPID 2,
which takes two long parameters and returns a void. OnObjectQuit is a CMySink member function that takes two longs and returns a void. This
function must be added manually and is called when the COM server fires a Quit
event.
//Instantiate the sink class and hold a pointer to it.
m_pSink = new CMySink();
//Get a pointer to sinks IUnknown, no AddRef. CMySink implements only
//dispinterface and the IUnknown and IDispatch pointers will be same.
LPUNKNOWN pUnkSink = m_pSink->GetIDispatch(FALSE);
//Establish a connection between source and sink.
//m_pUnkSrc is IUnknown of server obtained by CoCreateInstance().
//m_dwCookie is a cookie identifying the connection, and is needed
//to terminate the connection.
AfxConnectionAdvise(m_pUnkSrc, IID_MYEVENT, pUnkSink, FALSE,
&m_dwCookie);
//Get a pointer to sinks IUnknown, no AddRef. LPUNKNOWN pUnkSink = m_pSink->GetIDispatch(FALSE); //Terminate a connection between source and sink. //m_pUnkSrc is IUnknown of server obtained by CoCreateInstance(). //m_dwCookie is a value obtained through AfxConnectionAdvise(). AfxConnectionUnadvise(m_pUnkSrc, IID_MYEVENT, pUnkSink, FALSE, m_dwCookie);
152087 Connpts.exe sample demonstrates how to implement connection points and connection point sinks in Visual C++
Keywords: kbhowto KB181845