Expand Minimize

IGlobalInterfaceTable interface

Enables any apartment in a process to get access to an interface implemented on an object in any other apartment in the process.

When to implement

You should not implement this interface. The standard implementation provides complete thread-safe functionality.

When to use

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:


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



Note  When creating the global interface table object using the above call, you must link to the library Uuid.lib. This will resolve the external symbols CLSID_StdGlobalInterfaceTable and IID_IGlobalInterfaceTable.

There is a single instance of the global interface table per process, so all calls to this function in a process return the same instance.

After calling the CoCreateInstance function, register the interface you want to make available process-wide 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 the thread procedure using 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.

Members

The IGlobalInterfaceTable interface inherits from the IUnknown interface. IGlobalInterfaceTable also has these types of members:

Methods

The IGlobalInterfaceTable interface has these methods.

MethodDescription
GetInterfaceFromGlobal

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

RegisterInterfaceInGlobal

Registers the specified interface on an object residing in one apartment of a process as a global interface, enabling other apartments access to that interface.

RevokeInterfaceFromGlobal

Revokes the registration of an interface in the global interface table.

 

Remarks

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.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps | Windows Store apps]

Minimum supported server

Windows 2000 Server [desktop apps | Windows Store apps]

Header

ObjIdl.h

IDL

ObjIdl.idl

IID

IID_IGlobalInterfaceTable is defined as 00000146-0000-0000-C000-000000000046

 

 

Community Additions

ADD
Show:
© 2014 Microsoft