Cisco Cisco Computer Telephony Integration Option 9.0 Guía Del Desarrollador

Descargar
Página de 668
 
Chapter 4      Building Your Application
Using the COM CIL in Visual C++ 7.1(1)
4-20
CTI OS Developer’s Guide for Cisco ICM/IPCC Enterprise & Hosted Editions Release 7.1(1) 
if (m_pSessionResolver)
{
m_pSession = m_pSessionResolver->GetSession(_bstr_t(""));
}
Once the Session object is created, you can use it to make requests, and subscribe 
for events.
Subscribing and Unsubscribing to COM Events in C++
In this model, client applications subscribe for events by registering an instance 
of an event sink in the client with the event source. The COM Session object 
publishes several event interfaces (event sources), and clients can subscribe to any 
or all of them. 
To receive COM events, you must first create an event sink class, which should 
derive from a COM event sink class. The Comphone sample application uses the 
MFC class CCmdTarget.
class CEventSink : public CCmdTarget
{
//…
};
This class must implement the method signatures for the events it expects to 
receive. When an event is fired from the event source, the corresponding method 
in your event sink class will be invoked, and you can perform your custom event 
handling code at that time. 
To subscribe for an event, the client must call the AtlAdvise()  method, specifying 
a pointer to the interface of the event source.
// Add event sink as event listener for the _IallEvents interface
HRESULT hRes 
AtlAdvise(m_pSession, m_EventSink.GetIDispatch(FALSE),                      
__uuidof(_IAllEvents), &m_dwEventSinkAdvise);
When the program run is complete, the client must unsubscribe from the event 
source, using the AtlUnadvise() method:
// Unsubscribe from the Session object for the _IAllEvents interface
HRESULT hRes = 
AtlUnadvise( m_pSession, __uuidof(_IAllEvents), m_dwEventSinkAdvise );