RuntimeClass

表示继承指定接口的 WinRT 或 COM 类,并提供指定 Windows 运行时、经典 COM 和弱引用支持。

此类提供 WinRT 和 COM 类的样本实现,提供 QueryInterfaceAddRefRelease 等的实现,管理模块的引用计数,并支持为可激活对象提供类工厂。

语法

template <typename ...TInterfaces> class RuntimeClass
template <unsigned int classFlags, typename ...TInterfaces> class RuntimeClass;

参数

classFlags
可选参数。 一个或多个 RuntimeClassType 枚举值的组合。 可以定义 __WRL_CONFIGURATION_LEGACY__ 宏以更改项目中所有运行时类的 classFlags 的默认值。 如果已定义,则默认情况下,RuntimeClass 实例是非敏捷的。 如果未定义,则默认情况下,RuntimeClass 实例是敏捷的。 为了避免歧义,请始终指定 TInterfacesRuntimeClassType::InhibitFtmBase 中的 Microsoft::WRL::FtmBase。 如果同时使用 InhibitFtmBaseFtmBase,则对象将是敏捷的。

TInterfaces
对象所实现的接口列表,不包括 IUnknownIInspectable 或由 RuntimeClassType 控制的其他接口。 它还可能列出要派生的其他类,特别是 Microsoft::WRL::FtmBase,使对象敏捷并能够实现 IMarshal

成员

RuntimeClassInitialize
此函数在 MakeAndInitialize 函数模板用于构造对象时会初始化该对象。 如果对象已成功初始化,则返回 S_OK;如果初始化失败,则返回 COM 错误代码。 COM 错误代码作为返回值 MakeAndInitialize 传播。 如果使用 Make 函数模板构造对象,则不会调用 RuntimeClassInitialize 方法。

公共构造函数

名称 描述
RuntimeClass::RuntimeClass 初始化 RuntimeClass 类的当前实例。
RuntimeClass::~RuntimeClass 取消初始化 RuntimeClass 类的当前实例。

公共方法

名称 描述
RuntimeClass::AddRef 递增当前 RuntimeClass 对象的引用计数。
RuntimeClass::DecrementReference 递减当前 RuntimeClass 对象的引用计数。
RuntimeClass::GetIids 获取可包含当前 RuntimeClass 对象实现的接口 ID 的数组。
RuntimeClass::GetRuntimeClassName 获取当前 RuntimeClass 对象的运行时类名。
RuntimeClass::GetTrustLevel 获取当前 RuntimeClass 对象的信任级别。
RuntimeClass::GetWeakReference 获取指向当前 RuntimeClass 对象的弱引用对象的指针。
RuntimeClass::InternalAddRef 递增当前 RuntimeClass 对象的引用计数。
RuntimeClass::QueryInterface 检索指向指定接口 ID 的指针。
RuntimeClass::Release 对当前 RuntimeClass 对象执行 COM 版本操作。

继承层次结构

层次结构是实施详细信息。

要求

标头:implements.h

命名空间:Microsoft::WRL

RuntimeClass::~RuntimeClass

取消初始化 RuntimeClass 类的当前实例。

virtual ~RuntimeClass();

RuntimeClass::AddRef

递增当前 RuntimeClass 对象的引用计数。

STDMETHOD_(
   ULONG,
   AddRef
)();

返回值

如果成功,则为 S_OK;否则为指示错误的 HRESULT

RuntimeClass::DecrementReference

递减当前 RuntimeClass 对象的引用计数。

ULONG DecrementReference();

返回值

如果成功,则为 S_OK;否则为指示错误的 HRESULT

RuntimeClass::GetIids

获取可包含当前 RuntimeClass 对象实现的接口 ID 的数组。

STDMETHOD(
   GetIids
)
   (_Out_ ULONG *iidCount,
   _Deref_out_ _Deref_post_cap_(*iidCount) IID **iids);

参数

iidCount
此操作完成后,数组 iids 中的元素总数。

iids
此操作完成后,指向接口 ID 数组的指针。

返回值

如果成功,则为 S_OK;否则为 E_OUTOFMEMORY

RuntimeClass::GetRuntimeClassName

获取当前 RuntimeClass 对象的运行时类名。

STDMETHOD( GetRuntimeClassName )(
    _Out_ HSTRING* runtimeName
);

参数

runtimeName
此操作完成后,运行时类名称。

返回值

如果成功,则为 S_OK;否则为指示错误的 HRESULT

注解

如果 __WRL_STRICT____WRL_FORCE_INSPECTABLE_CLASS_MACRO__ 未定义断言错误,则会发出断言错误。

RuntimeClass::GetTrustLevel

获取当前 RuntimeClass 对象的信任级别。

STDMETHOD(GetTrustLevel)(
    _Out_ TrustLevel* trustLvl
);

参数

trustLvl
此操作完成后,当前 RuntimeClass 对象的信任级别。

返回值

总是为 S_OK

备注

如果 __WRL_STRICT____WRL_FORCE_INSPECTABLE_CLASS_MACRO__ 未定义断言错误,则会发出断言错误。

RuntimeClass::GetWeakReference

获取指向当前 RuntimeClass 对象的弱引用对象的指针。

STDMETHOD(
   GetWeakReference
)(_Deref_out_ IWeakReference **weakReference);

参数

weakReference
此操作完成后,指向弱引用对象的指针。

返回值

总是为 S_OK

RuntimeClass::InternalAddRef

递增当前 RuntimeClass 对象的引用计数。

ULONG InternalAddRef();

返回值

生成的引用计数。

RuntimeClass::QueryInterface

检索指向指定接口 ID 的指针。

STDMETHOD(
   QueryInterface
)
   (REFIID riid,
   _Deref_out_ void **ppvObject);

参数

riid
接口 ID。

ppvObject
此操作完成后,指向 riid 参数指定的接口的指针。

返回值

如果成功,则为 S_OK;否则为指示错误的 HRESULT

RuntimeClass::Release

对当前 RuntimeClass 对象执行 COM 版本操作。

STDMETHOD_(
   ULONG,
   Release
)();

返回值

如果成功,则为 S_OK;否则为指示错误的 HRESULT

备注

如果引用计数变为零,则将删除 RuntimeClass 对象。

RuntimeClass::RuntimeClass

初始化 RuntimeClass 类的当前实例。

RuntimeClass();