Accessing Interfaces Across Apartments

COM provides a way for any apartment in a process to get access to an interface implemented on an object in any other apartment in the process. This is done through the IGlobalInterfaceTable interface. This interface has three methods, which 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 process-wide variables and agile objects (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 might 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.

Note

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.

 

For information about creating and using a global interface table, see the following topics:

Choosing the Threading Model

Multithreaded Apartments

In-Process Server Threading Issues

Processes, Threads, and Apartments

Single-Threaded and Multithreaded Communication

Single-Threaded Apartments