Cisco Cisco Computer Telephony Integration Option 9.0 Developer's Guide

Page of 500
   
4-13
CTI OS Developer’s Guide for Cisco ICM/IPCC Enterprise & Hosted Editions
Cisco CTI OS Release 7.2(1)
Chapter 4      Building Your Application
Using the COM CIL in Visual C++ 7.1(1)
Important Note About COM Method Syntax
In this manual, the syntax used to describe method calls in COM shows standard COM data types such 
as BSTR, VARIANT and SAFEARRAY. Be aware that depending on the development environment, 
tools, and the manner how the COM CIL is included in your project application, these data types can be 
encapsulated by wrapper classes proper to the environment. 
For example, in a Microsoft Visual C++ 7.1(1) project a VARIANT type can be either a CComVariant 
or _variant_t, and a BSTR type can be either a CComBSTR or _bstr_t.
For more information, see the documentation for your development environment.
Using the CIL Dynamic Link Libraries
Next, you must import the COM Dynamic Link Libraries into your C++ application. The following code 
sample (which you might put into your StdAfx.h file) depicts how to use a COM Dynamic Link Library 
in C++:
#import "..\..\Distribution\COM\ctiossessionresolver.dll" using namespace CTIOSSESSIONRESOLVERLib;
#import "..\..\Distribution\COM\ctiosclient.dll" using namespace CTIOSCLIENTLib;
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
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
{
//…
};