RuntimeClass class

Represents a WinRT or COM class that inherits the specified interfaces and provides the specified Windows Runtime, classic COM, and weak reference support.

This class provides the boilerplate implementation of WinRT and COM classes, providing the implementation of QueryInterface, AddRef, Release etc., manages the reference count of the module and has support for providing the class factory for activatable objects.

Syntax

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

Parameters

classFlags
Optional parameter. A combination of one or more RuntimeClassType enumeration values. The __WRL_CONFIGURATION_LEGACY__ macro can be defined to change the default value of classFlags for all runtime classes in the project. If defined, RuntimeClass instances are non-agile by default. When not defined, RuntimeClass instances are agile by default. To avoid ambiguity, always specify the Microsoft::WRL::FtmBase in TInterfaces or RuntimeClassType::InhibitFtmBase. If InhibitFtmBase and FtmBase are both used, the object will be agile.

TInterfaces
The list of interfaces the object implements beyond IUnknown, IInspectable or other interfaces controlled by RuntimeClassType. It also may list other classes to be derived from, notably Microsoft::WRL::FtmBase to make the object agile and cause it to implement IMarshal.

Members

RuntimeClassInitialize
A function that initializes the object if the MakeAndInitialize function template is used to construct the object. It returns S_OK if the object was successfully initialized, or a COM error code if initialization failed. The COM error code is propagated as the return value of MakeAndInitialize. The RuntimeClassInitialize method isn't called if the Make function template is used to construct the object.

Public Constructors

Name Description
RuntimeClass::RuntimeClass Initializes the current instance of the RuntimeClass class.
RuntimeClass::~RuntimeClass Deinitializes the current instance of the RuntimeClass class.

Public Methods

Name Description
RuntimeClass::AddRef Increments the reference count for the current RuntimeClass object.
RuntimeClass::DecrementReference Decrements the reference count for the current RuntimeClass object.
RuntimeClass::GetIids Gets an array that can contain the interface IDs implemented by the current RuntimeClass object.
RuntimeClass::GetRuntimeClassName Gets the runtime class name of the current RuntimeClass object.
RuntimeClass::GetTrustLevel Gets the trust level of the current RuntimeClass object.
RuntimeClass::GetWeakReference Gets a pointer to the weak reference object for the current RuntimeClass object.
RuntimeClass::InternalAddRef Increments the reference count to the current RuntimeClass object.
RuntimeClass::QueryInterface Retrieves a pointer to the specified interface ID.
RuntimeClass::Release Performs a COM Release operation on the current RuntimeClass object.

Inheritance Hierarchy

The hierarchy is an implementation detail.

Requirements

Header: implements.h

Namespace: Microsoft::WRL

RuntimeClass::~RuntimeClass

Deinitializes the current instance of the RuntimeClass class.

virtual ~RuntimeClass();

RuntimeClass::AddRef

Increments the reference count for the current RuntimeClass object.

STDMETHOD_(
   ULONG,
   AddRef
)();

Return value

S_OK if successful; otherwise, an HRESULT that indicates the error.

RuntimeClass::DecrementReference

Decrements the reference count for the current RuntimeClass object.

ULONG DecrementReference();

Return value

S_OK if successful; otherwise, an HRESULT that indicates the error.

RuntimeClass::GetIids

Gets an array that can contain the interface IDs implemented by the current RuntimeClass object.

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

Parameters

iidCount
When this operation completes, the total number of elements in array iids.

iids
When this operation completes, a pointer to an array of interface IDs.

Return value

S_OK if successful; otherwise, E_OUTOFMEMORY.

RuntimeClass::GetRuntimeClassName

Gets the runtime class name of the current RuntimeClass object.

STDMETHOD( GetRuntimeClassName )(
    _Out_ HSTRING* runtimeName
);

Parameters

runtimeName
When this operation completes, the runtime class name.

Return value

S_OK if successful; otherwise, an HRESULT that indicates the error.

Remarks

An assert error is emitted if __WRL_STRICT__ or __WRL_FORCE_INSPECTABLE_CLASS_MACRO__ isn't defined.

RuntimeClass::GetTrustLevel

Gets the trust level of the current RuntimeClass object.

STDMETHOD(GetTrustLevel)(
    _Out_ TrustLevel* trustLvl
);

Parameters

trustLvl
When this operation completes, the trust level of the current RuntimeClass object.

Return value

Always S_OK.

Remarks

An assert error is emitted if __WRL_STRICT__ or __WRL_FORCE_INSPECTABLE_CLASS_MACRO__ isn't defined.

RuntimeClass::GetWeakReference

Gets a pointer to the weak reference object for the current RuntimeClass object.

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

Parameters

weakReference
When this operation completes, a pointer to a weak reference object.

Return value

Always S_OK.

RuntimeClass::InternalAddRef

Increments the reference count to the current RuntimeClass object.

ULONG InternalAddRef();

Return value

The resulting reference count.

RuntimeClass::QueryInterface

Retrieves a pointer to the specified interface ID.

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

Parameters

riid
An interface ID.

ppvObject
When this operation completes, a pointer to the interface specified by the riid parameter.

Return value

S_OK if successful; otherwise, an HRESULT that indicates the error.

RuntimeClass::Release

Performs a COM Release operation on the current RuntimeClass object.

STDMETHOD_(
   ULONG,
   Release
)();

Return value

S_OK if successful; otherwise, an HRESULT that indicates the error.

Remarks

If the reference count becomes zero, the RuntimeClass object is deleted.

RuntimeClass::RuntimeClass

Initializes the current instance of the RuntimeClass class.

RuntimeClass();