Share via


Use a Factory Object to Obtain an Interface Pointer

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.

Factory objects are defined by the API. For example, in Unified Communications Client API, a platform object serves as the factory object to create endpoints; that is, to obtain IUccEndpoint interface pointers. In the following code example, a URI manager (IUccUriManager) serves as the factory object to obtain the IUccUri interface pointers.

CComPtr<IUccUriManager> pIUccUriManager;
CComPtr<IUccUri> spUccUri;
CComBSTR bstrUri = L”sip:john@contoso.com”;
HRESULT hr;

hr = CoCreateInstance(__uuidof(UccUriManager),
                      NULL,
                      CLSCTX_INPROC_SERVER,
                      __uuidof(IUccUriManager),
                      (LPVOID *)&pIUccUriManager);
if (FAILED(hr) || hr == S_FALSE)
{
// Failed to co-create UccUriManager class and to obtain
// an IUccUriManager interface pointer.
Return S_FALSE;
}
// Use pIUccUriManager as a factory object 
// to obtain an IUccUri interface pointer.
hr =  pIUccUriManager->ParseUri(bstrUri, &spUccUri);
if ((FAILED(hr)) || (hr == S_FALSE))
{
    // Failed to obtain the IUccUri interface pointer.
    return S_FALSE;
}

CComPtr<IUccEndpoint> pIUccEndpoint;

// Use pIUccPlatform as a factoryCreate to obtain an
// IUccEndpoint interface pointer.
hr = pIUccPlatform->CreateEndpoint(pIUccUri, NULL, NULL, &pIUccEndpoint );
    
if ((FAILED(hr)) || (hr == S_FALSE))
{
    return S_FALSE;
}

See Also

Concepts

Obtaining Unified Communications Client API Interface Pointers
Obtain an Interface Pointer Through a Co-creatable Co-class
Call QueryInterface on an Existing Interface Pointer