Share via


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 實例預設為敏捷式。 若要避免模棱兩可,請一律在 或 RuntimeClassType::InhibitFtmBaseTInterfaces 指定 Microsoft::WRL::FtmBase 。 如果使用 InhibitFtmBaseFtmBase ,物件將會是敏捷式的。

TInterfaces
物件所實作的介面清單超出 IUnknownIInspectable ,或由 RuntimeClassType 所控制的其他介面。 它也可以列出衍生自 的其他類別,特別是 Microsoft::WRL::FtmBase 讓物件變得敏捷,並導致它實 IMarshal 作 。

成員

RuntimeClassInitialize
如果函式範本用來建構物件, MakeAndInitialize 則會初始化 物件的函式。 如果物件已成功初始化,則傳 S_OK 回 ,如果初始化失敗,則會傳回 COM 錯誤碼。 COM 錯誤碼會傳播為 的 MakeAndInitialize 傳回值。 RuntimeClassInitialize如果使用函式範本來建構物件, Make 則不會呼叫 方法。

公用建構函式

名稱 描述
RuntimeClass::RuntimeClass 初始化 類別的 RuntimeClass 目前實例。
RuntimeClass::~RuntimeClass 將 類別的 RuntimeClass 目前實例取消初始化。

公用方法

名稱 描述
RuntimeClass::AddRef 遞增目前 RuntimeClass 物件的參考計數。
RuntimeClass::DecrementReference 遞減目前 RuntimeClass 物件的參考計數。
RuntimeClass::GetIids 取得陣列,這個陣列可以包含目前 RuntimeClass 物件所實作的介面識別碼。
RuntimeClass::GetRuntimeClassName 取得目前 RuntimeClass 物件的執行時間類別名稱。
RuntimeClass::GetTrustLevel 取得目前 RuntimeClass 物件的信任層級。
RuntimeClass::GetWeakReference 取得目前 RuntimeClass 物件的弱式參考物件的指標。
RuntimeClass::InternalAddRef 將參考計數遞增至目前的 RuntimeClass 物件。
RuntimeClass::QueryInterface 擷取指定介面識別碼的指標。
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 物件所實作的介面識別碼。

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

參數

iidCount
當此作業完成時,陣列 iids 中的專案總數。

iids
此作業完成時,介面識別碼陣列的指標。

傳回值

如果成功即為 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

擷取指定介面識別碼的指標。

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

參數

riid
介面識別碼。

ppvObject
當此作業完成時,參數所 riid 指定的介面指標。

傳回值

S_OK 如果成功,則為 ;否則, HRESULT 表示錯誤的 。

RuntimeClass::Release

在目前 RuntimeClass 物件上執行 COM 發行作業。

STDMETHOD_(
   ULONG,
   Release
)();

傳回值

S_OK 如果成功,則為 ;否則, HRESULT 表示錯誤的 。

備註

如果參考計數變成零,則會 RuntimeClass 刪除物件。

RuntimeClass::RuntimeClass

初始化 類別的 RuntimeClass 目前實例。

RuntimeClass();