Cisco Cisco Computer Telephony Integration Option 8.5 Developer's Guide

Page of 500
   
4-13
CTI OS Developer’s Guide for Cisco Unified ICM/Contact Center Enterprise & Hosted
Release 7.5(1)
Chapter 4      Building Your Application
Using the COM CIL in Visual C++ 7.5(1)
Note
You must register three DLLs, but you do not need to import the arguments.dll into your project since it 
is imported by the ctiosclient.dll type library.
Creating an Instance of a COM Object
Note
Only the apartment threading model is supported. The free threading model is not supported.
COM objects in C++ are created via the COM runtime library. To create a COM object at run time, your 
program will need to use the CreateInstance() method call. 
// Create SessionResolver and Session object
hRes = m_pSessionResolver.CreateInstance    (OLESTR("CTIOSSessionResolver.SessionResolver"));
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 );