Cisco Cisco Computer Telephony Integration Option 8.5 Developer's Guide

Page of 546
 
Chapter 4      Building Your Application
Using the COM CIL in C++
4-18
Cisco ICM Software CTI OS Developer’s Guide Release 6.0(0)
Creating an Instance of a COM Object
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