Home COM GDI+ WebBrowser Data Access

IGlobalInterfaceTable Interface

 

IID_IGlobalInterfaceTable

{00000146-0000-0000-C000-000000000046}

 

 

Allows any apartment in a process to get access to an interface implemented on an object in any other apartment in the process. The three methods allow you to do the following:

  • Register an interface as a global (processwide) interface.

  • Get a pointer to that interface from any other apartment through a cookie.

  • Revoke the global registration of an interface.

The IGlobalInterfaceTable interface is an efficient way for a process to store an interface pointer in a memory location that can be accessed from multiple apartments within the process, such as processwide variables and agile (free-threaded marshaled) objects containing interface pointers to other objects.

 

An agile object is unaware of the underlying COM infrastructure in which it runs—in other words, what apartment, context, and thread it is executing on. The object may be holding on to interfaces that are specific to an apartment or context. For this reason, calling these interfaces from wherever the agile component is executing may not always work properly. The global interface table avoids this problem by guaranteeing that a valid proxy (or direct pointer) to the object is used, based on where the agile object is executing.

 

The global interface table is not portable across process or machine boundaries, so it cannot be used in place of the normal parameter-passing mechanism.

 

Use this interface when an interface implemented on an object in one apartment must be stored in memory accessible for use by other apartments. To create the global interface table object and get a pointer to this interface, make the following call:

 

C++

 

CoCreateInstance(CLSID_StdGlobalInterfaceTable,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IGlobalInterfaceTable,
    (void **)&gpGIT)

 

PowerBasic

 

CoCreateInstance(CLSID_StdGlobalInterfaceTable, _

    BYVAL %NULL, _

    %CLSCTX_INPROC_SERVER, _

    IID_IGlobalInterfaceTable, _

    gpGIT)
 

After calling the CoCreateInstance function, register the interface you want to make available processwide from the apartment in which it resides with a call to the RegisterInterfaceInGlobal method. This supplies a pointer to a "cookie" (through the pdwCookie parameter) that identifies the interface and its location. An apartment that wants a pointer to this interface then calls the GetInterfaceFromGlobal method with this cookie, and the implementation then supplies an interface pointer to the calling apartment. To revoke the interface's global registration, any apartment may call the RevokeInterfaceFromGlobal method.

 

A simple example of its use would be when you want to pass an interface pointer on an object in a single-threaded apartment (STA) to a worker thread in another apartment. Rather than having to marshal it into a stream and pass the stream to the worker thread as a thread parameter, this interface allows you simply to pass a cookie.

 

When you register the interface in the global interface table, you get a cookie that you can use instead of passing the actual pointer whenever you need to pass the pointer either to a nonmethod parameter that is going to another apartment (as a parameter to ThreadProc via CreateThread) or to in-process memory accessible outside your apartment.

 

Care is required because using globals places the extra burden on the programmer of managing problems such as race conditions and mutual exclusion, which are associated with accessing global state from multiple threads simultaneously.

 

 

Methods in VTable order

IUnknown Methods

Description

QueryInterface

Returns pointers to supported interfaces.

AddRef

Increments reference count.

Release

Decrements reference count.

IGlobalInterfaceTable Methods

Description

RegisterInterfaceInGlobal

Registers a specified interface on an object residing in one apartment of a process as a global (processwide) interface, allowing other apartments access to that interface.

RevokeInterfaceFromGlobal

Revokes the registration of an interface in the global (processwide) interface table.

GetInterfaceFromGlobal

Supplies a pointer to an interface on an object that is usable by the calling apartment.

 

RegisterInterfaceInGlobal

 

FUNCTION IGlobalInterfaceTable_RegisterInterfaceInGlobal ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pUnk AS DWORD _

, BYREF riid AS GUID _

, BYREF pdwCookie AS DWORD _

) AS LONG
 

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[3] USING IGlobalInterfaceTable_RegisterInterfaceInGlobal (pthis, pUnk, riid, pdwCookie) TO HRESULT
  FUNCTION = HRESULT
 

END FUNCTION

 

 

 

FUNCTION IGlobalInterfaceTable_RegisterInterfaceInGlobal ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pUnk AS DWORD _

, BYREF riid AS GUID _

, BYREF pdwCookie AS DWORD _

) AS LONG
 

  ! push pdwCookie

  ! mov  eax, riid

  ! push eax

  ! push pUnk

  ! mov  eax, pthis

  ! push eax

  ! mov  eax, dword ptr[eax]

  ! call dword ptr[eax+12]

  ! mov  function, eax
 

END FUNCTION

 

 

RevokeInterfaceFromGlobal

 

FUNCTION IGlobalInterfaceTable_RevokeInterfaceFromGlobal ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL dwCookie AS DWORD _

) AS LONG
 

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[4] USING IGlobalInterfaceTable_RevokeInterfaceFromGlobal (pthis, dwCookie) TO HRESULT
  FUNCTION = HRESULT
 

END FUNCTION

 

 

 

FUNCTION IGlobalInterfaceTable_RevokeInterfaceFromGlobal ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL dwCookie AS DWORD _

) AS LONG
 

  ! push pdwCookie

  ! mov  eax, pthis

  ! push eax

  ! mov  eax, dword ptr[eax]

  ! call dword ptr[eax+16]

  ! mov  function, eax

 

END FUNCTION

 

 

GetInterfaceFromGlobal

 

FUNCTION IGlobalInterfaceTable_GetInterfaceFromGlobal ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL dwCookie AS DWORD _

, BYREF riid AS GUID _

, BYREF ppv AS DWORD _

) AS LONG
 

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[5] USING IGlobalInterfaceTable_GetInterfaceFromGlobal (pthis, dwCookie, riid, ppv) TO HRESULT
  FUNCTION = HRESULT
 

END FUNCTION

 

 

 

FUNCTION IGlobalInterfaceTable_GetInterfaceFromGlobal ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL dwCookie AS DWORD _

, BYREF riid AS GUID _

, BYREF ppv AS DWORD _

) AS LONG
 

  ! push ppv

  ! mov  eax, riid

  ! push eax

  ! push dwCookie

  ! mov  eax, pthis

  ! push eax

  ! mov  eax, dword ptr[eax]

  ! call dword ptr[eax+20]

  ! mov  function, eax

 

END FUNCTION

 

 

Page last updated on Friday, 17 March 2006 17:20:43 +0100