大网数据广告活动
Windows 系统接口

Accessing Interfaces Across Apartments

· 52CE 我爱测

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:

Related topics

Choosing the Threading Model

Multithreaded Apartments

In-Process Server Threading Issues

Processes, Threads, and Apartments

Single-Threaded and Multithreaded Communication

Single-Threaded Apartments

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。