Obtain an Interface Pointer Through a Co-creatable Co-class
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Creating a co-creatable class involves calling the CoCreateInstance function exposed by the COM library. A successful call to this function returns a pointer to the default interface of the co-class. Before calling CoCreateInstance, make sure that the COM library is properly initialized.
In Unified Communications Client API, UccPlatform is a co-creatable co-class and is used to obtain the IUccPlatform interface pointer. The following example is a code snippet drawn from an MFC sample application (installed as part of Unified Communications Client API).
// Initialize the COM library
HRESULT hr = CoInitialize(0);
if (FAILED(hr))
// CoInitialize failed
return hr;
// Obtain a pointer to the IUccPlatform interface
// by way of the cocreatable UccPlatform class.
CComPtr<IUccPlatform> pIUccPlatform;
hr = CoCreateInstance(
__uuidof(UccPlatform),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IUccPlatform),
(LPVOID *)&pIUccPlatform
);
if (FAILED(hr))
return hr;
CComBSTR bstrAppName = L"UccApiSampleApp";
hr = pIUccPlatform->Initialize( bstrAppName);
if (FAILED(hr))
return false;
In MFC, the CComPtr<T>
template class encapsulates a pointer (T*
) to the type T
. Therefore, in the previous code snippet, CComPtr<IUccPlatform>
is the smart pointer version of IUccPlatform*
.
See Also
Concepts
Obtaining Unified Communications Client API Interface Pointers
Call QueryInterface on an Existing Interface Pointer
Use a Factory Object to Obtain an Interface Pointer