ComWrappers 类

定义

重要

此 API 不符合 CLS。

用于管理 COM IUnknown 类型的包装器的类。

public ref class ComWrappers abstract
[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public abstract class ComWrappers
[System.CLSCompliant(false)]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public abstract class ComWrappers
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
type ComWrappers = class
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
type ComWrappers = class
Public MustInherit Class ComWrappers
继承
ComWrappers
派生
属性

注解

ComWrappers API 提供对 IUnknown API 的支持,而与内置的 COM 互操作性支持无关。 API ComWrappers 公开了开发人员以高效方式替换内置版本所需的最小运行时支持。

传统上,在运行时中,托管对象的本机代理称为 COM 可调用包装器(CCW),而本机对象的托管代理称为运行时可调用包装器(RCW)。 但是,在此处使用时,不应将这些术语与同名的内置功能(即 CCWRCW)混淆。 与内置功能不同,准确的生命周期管理、调度方法以及参数和返回值的封送的大部分责任都留给了 ComWrappers 实现者。

“最低支持”由以下功能定义:

  1. 托管对象和本机代理(例如,CCW)之间的高效映射。
  2. 本机 IUnknown 与其托管代理(例如,RCW)之间的高效映射。
  3. 通过 IReferenceTrackerHost 接口协定与垃圾回收器集成。

利用这一点是一个高级方案。

代理状态

本部分提供关于本机代理状态和托管代理状态在各自创建后的描述和图示。

在下图中,强引用被描述为实线(===),弱引用被描述为虚线(= = =)。 术语“强引用”和“弱引用”应解释为“延长生存期”和“不延长生存期”,而不是暗示特定实现。

下图显示了调用 ComWrappers.GetOrCreateComInterfaceForObject(Object, CreateComInterfaceFlags)后托管对象和本机代理的状态。

 --------------------                  ----------------------
|   Managed object   |                |     Native proxy     |
|                    |                | Ref count: 1         |
|  ----------------  |                |  ------------------  |
| | Weak reference |=| = = = = = = = >| | Strong reference | |
| |    to proxy    | |<===============|=|    to object     | |
|  ----------------  |                |  ------------------  |
 --------------------                  ----------------------

下图显示了调用 ComWrappers.GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags) 后本机对象和托管代理的状态。 “身份认同”的概念遵循相关规则IUnknown

 ------------------               ------------------
|  Native object   |< = = = = = =|                  |
| Ref count: +1    |             | Mapping from     |
 ------------------              | native identity  |
 ------------------------        | to managed proxy |
|   Managed proxy        |< = = =|                  |
| Created by ComWrappers |        ------------------
|   implementer.        |
| Optional AddRef() on   |
|   native object.      |
 ------------------------

请注意,从运行时的角度来看,只有弱引用存在。 +1 假定本机对象的引用计数由托管代理的创建者(即 ComWrappers 实现者)执行,以确保本机对象及其托管代理之间的生命周期相符。 托管代理中提到了可选的强引用(即 AddRef()),该引用用于支持前面提到的方案(3)。 请参阅 CreateObjectFlags.TrackerObject。 使用此可选强引用时,引用计数将为 +2

构造函数

名称 说明
ComWrappers()

实例构造函数。

方法

名称 说明
ComputeVtables(Object, CreateComInterfaceFlags, Int32)

计算所需的 Vtable, obj以尊重其 flags值。

CreateObject(IntPtr, CreateObjectFlags, Object, CreatedWrapperFlags)

通过 externalComObject 遵循 的值 flags为指向的对象创建托管对象。

CreateObject(IntPtr, CreateObjectFlags)

为指向的对象 externalComObject 创建一个托管对象,并遵循其值 flags

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetIUnknownImpl(IntPtr, IntPtr, IntPtr)

获取运行时提供的 IUnknown 实现。

GetOrCreateComInterfaceForObject(Object, CreateComInterfaceFlags)

创建可传递给非托管环境的提供的对象的 COM 表示形式。

GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags, Object)

获取当前注册的托管对象或创建新的托管对象并注册它。

GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags)

获取当前注册的托管对象或创建新的托管对象并注册它。

GetOrRegisterObjectForComInstance(IntPtr, CreateObjectFlags, Object, IntPtr)

获取当前已注册的托管对象或使用提供的托管对象并注册它。

GetOrRegisterObjectForComInstance(IntPtr, CreateObjectFlags, Object)

获取当前注册的托管对象或使用提供的托管对象并注册它。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
RegisterForMarshalling(ComWrappers)

ComWrappers注册要用作在运行时中封送的全局实例的实例。

RegisterForTrackerSupport(ComWrappers)

ComWrappers注册要用作引用跟踪器支持的全局实例的实例。

ReleaseObjects(IEnumerable)

释放普通对象或 COM 接口生存期之外的对象的集合。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
TryGetComInstance(Object, IntPtr)

确定指定的托管对象是否为 ComWrappers已创建的托管包装器,如果是这样,则返回包装的非托管指针。

TryGetObject(IntPtr, Object)

确定指定的 COM 对象是否为 ComWrappers创建的非托管包装器,如果是这样,则返回包装的托管对象。

适用于