IServiceProviderImpl Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

This class provides a default implementation of the IServiceProvider interface.

template <class T>   class ATL_NO_VTABLE IServiceProviderImpl :  public IServiceProvider

Parameters

T
Your class, derived from IServiceProviderImpl.

Public Methods

NameDescription
IServiceProviderImpl::QueryServiceCreates or accesses the specified service and returns an interface pointer to the specified interface for the service.

The IServiceProvider interface locates a service specified by its GUID and returns the interface pointer for the requested interface on the service. Class IServiceProviderImpl provides a default implementation of this interface.

IServiceProviderImpl specifies one method: QueryService, which creates or accesses the specified service and returns an interface pointer to the specified interface for the service.

IServiceProviderImpl uses a service map, starting with BEGIN_SERVICE_MAP and ending with END_SERVICE_MAP.

The service map contains two entries: SERVICE_ENTRY, which indicates a specified service id (SID) supported by the object, and SERVICE_ENTRY_CHAIN, which calls QueryService to chain to another object.

IServiceProvider

IServiceProviderImpl

Header: atlcom.h

Creates or accesses the specified service and returns an interface pointer to the specified interface for the service.

STDMETHOD(QueryService)(REFGUID guidService,
    REFIID riid,
    void** ppvObject);

Parameters

[IN] guidService
Pointer to a service identifier (SID).

[IN] riid
Identifier of the interface to which the caller is to gain access.

[OUT] ppvObj
Indirect pointer to the requested interface.

Return Value

The returned HRESULT value is one of the following:

Return valueMeaning
S_OKThe service was successfully created or retrieved.
E_INVALIDARGOne or more of the arguments is invalid.
E_OUTOFMEMORYMemory is insufficient to create the service.
E_UNEXPECTEDAn unknown error occurred.
E_NOINTERFACEThe requested interface is not part of this service, or the service is unknown.

Remarks

QueryService returns an indirect pointer to the requested interface in the specified service. The caller is responsible for releasing this pointer when it is no longer required.

When you call QueryService, you pass both a service identifier ( guidService) and an interface identifier ( riid). The guidService specifies the service to which you want access, and the riid identifies an interface that is part of the service. In return, you receive an indirect pointer to the interface.

The object that implements the interface might also implement interfaces that are part of other services. Consider the following:

  • Some of these interfaces might be optional. Not all interfaces defined in the service description are necessarily present on every implementation of the service or on every returned object.

  • Unlike calls to QueryInterface, passing a different service identifier does not necessarily mean that a different Component Object Model (COM) object is returned.

  • The returned object might have additional interfaces that are not part of the definition of the service.

Two different services, such as SID_SMyService and SID_SYourService, can both specify the use of the same interface, even though the implementation of the interface might have nothing in common between the two services. This works, because a call to QueryService (SID_SMyService, IID_IDispatch) can return a different object than QueryService (SID_SYourService, IID_IDispatch). Object identity is not assumed when you specify a different service identifier.

Class Overview

Show: