Home COM GDI+ WebBrowser Data Access

IServiceProvider Interface

 

IID_IServiceProvider

{6D5140C1-7436-11CE-8034-00AA006009FA}

 

 

The IServiceProvider interface is a generic access mechanism to locate a globally unique identifier (GUID) identified service.

Remarks

The IServiceProvider interface is a generic access mechanism to locate a GUID-identified service that is provided through a control or any other object with which it can communicate. For example, an embedded object (such as an OLE control) normally only communicates with its associated client site object in the container through the IOleClientSite interface supplied through IOleObject::SetClientSite. Such an embedded object is required to ask the client site for some other service that the container supports when that service may not necessarily be implemented in the site itself.

In this regard, the site must provide a means through which the control managed by that site can access the service when necessary. A specific example of this necessity can be found in the function IOleInPlaceSite::GetWindowContext, through which an in-place object or control can access interface pointers for the document object that contains the site and the frame object that contains the document. Because these interface pointers exists on separate objects, the control cannot call the site's QueryInterface to obtain those pointers. Instead, use the IServiceProvider interface.

The IServiceProvider interface has only one member, QueryService, through which a caller specifies the service ID (SID, a GUID), the interface identifier (IID) of the interface desired in return, and the address of the caller's interface pointer variable.
 

 

Methods in VTable order

IUnknown Methods

Description

QueryInterface

Returns pointers to supported interfaces.

AddRef

Increments reference count.

Release

Decrements reference count.

IServiceProvider Members

Description

QueryService

Acts as the factory method for any services exposed through an implementation of IServiceProvider.

 

QueryService

 

FUNCTION IServiceProvider_QueryService ( _
  BYVAL
pthis AS DWORD PTR _

, BYREF guidService AS GUID _

, BYREF riid AS GUID _

, BYREF ppv AS DWORD _

  ) AS LONG


  LOCAL
HRESULT AS LONG
  CALL DWORD
@@pthis[3] USING IServiceProvider_QueryService (pthis, guidService, riid, ppv) TO HRESULT
  FUNCTION =
HRESULT

END FUNCTION
 

 

IserviceProvider interface implementation

 


$IID_IServiceProvider = GUID$("{6D5140C1-7436-11CE-8034-00AA006009FA")

' ****************************************************************************************
' IServiceProvider interface
' ****************************************************************************************
TYPE IServiceProviderVtbl
   ' IUnknown methods
   pQueryInterface          AS DWORD          ' // QueryInterface method
   pAddRef                  AS DWORD          ' // AddRef method
   pRelease                 AS DWORD          ' // Release method
   ' IServiceProvider members
   pQueryService            AS DWORD          ' // QueryService method
   ' Custom data
   pVtblAddr                AS DWORD          ' // Address of the virtual table
   cRef                     AS DWORD          ' // Reference count
END TYPE
' ****************************************************************************************

' ****************************************************************************************
' Builds the IServiceProvider Virtual Table
' Returns a cookie that is a pointer to a IServiceProviderVtbl structure.
' ****************************************************************************************
FUNCTION IServiceProvider_BuildVtbl () AS DWORD

   LOCAL pVtbl AS IServiceProviderVtbl PTR
   LOCAL pUnk AS IServiceProviderVtbl PTR

   pVtbl = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, SIZEOF(@pVtbl))
   IF pVtbl = 0 THEN EXIT FUNCTION

   @pVtbl.pQueryInterface          = CODEPTR(IServiceProvider_QueryInterface)
   @pVtbl.pAddRef                  = CODEPTR(IServiceProvider_AddRef)
   @pVtbl.pRelease                 = CODEPTR(IServiceProvider_Release)

   @pVtbl.pQueryService            = CODEPTR(IServiceProvider_QueryService)

   @pVtbl.pVtblAddr                = pVtbl
   @pVtbl.cRef                     = 1

   pUnk = VARPTR(@pVtbl.pVtblAddr)
   FUNCTION = pUnk

END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' IServiceProvider_QueryInterface method
' Returns the IUnknown of our class and increments the reference counter.
' ****************************************************************************************
FUNCTION IServiceProvider_QueryInterface (BYVAL pCookie AS IServiceProviderVtbl PTR, BYREF riid AS GUID, BYREF ppvObj AS DWORD) AS LONG
   IF riid = $IID_IServiceProvider THEN
      ppvObj = pCookie
      INCR @@pCookie.cRef
      FUNCTION = %S_OK
   ELSE
      FUNCTION = %E_NOINTERFACE
   END IF
END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' IServiceProvider_AddRef method
' Increments the reference counter.
' ****************************************************************************************
FUNCTION IServiceProvider_AddRef (BYVAL pCookie AS IServiceProviderVtbl PTR) AS DWORD
   INCR @@pCookie.cRef
   FUNCTION = @@pCookie.cRef
END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' IServiceProvider_Release method
' Releases our class if there is only a reference to him and decrements the reference counter.
' ****************************************************************************************
FUNCTION IServiceProvider_Release (BYVAL pCookie AS IServiceProviderVtbl PTR) AS DWORD
   DECR @@pCookie.cRef
   FUNCTION = @@pCookie.cRef
   IF @@pCookie.cRef = 0 THEN
      IF ISTRUE @@pCookie.pVtblAddr THEN
         HeapFree(GetProcessHeap(), 0, BYVAL @@pCookie.pVtblAddr)
      END IF
   END IF
END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' Acts as the factory method for any services exposed through an implementation of
' IServiceProvider.
' ****************************************************************************************
FUNCTION IServiceProvider_QueryService (BYVAL pCookie AS IServiceProviderVtbl PTR, BYREF guidService AS GUID, BYREF riid AS GUID, BYREF ppv AS DWORD) AS LONG
   ' Put your code here
   ' FUNCTION = %S_OK, %E_NOINTERFACE, %E_OUTOFMEMORY, or %E_UNEXPECTED
END FUNCTION
' ****************************************************************************************
 

 

Page last updated on Monday, 03 April 2006 20:25:35 +0200