Every C++/WinRT runtime class (whether a Windows or a third party runtime class) derives from winrt::Windows::Foundation::IUnknown. It represents the COM IUnknown interface, and it provides facilities such as querying for a different interface, abi functions, and comparison operators.
Syntax
struct IUnknown
Requirements
サポートされている最小 SDK: Windows SDK バージョン 10.0.17134.0 (Windows 10 バージョン 1803)
Namespace: winrt
Header: %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)
Constructors
Constructor | Description |
---|---|
IUnknown::IUnknown constructor | Initializes a new instance of the IUnknown struct, optionally with a copy or move of the input data. |
Member functions
Function | Description |
---|---|
IUnknown::as function | インターフェイスを要求し、サポートされていない場合はスローします。 |
IUnknown::try_as function | インターフェイスを要求し、サポートされていない場合は null を生成します。 |
IUnknown::try_as_with_reason function | インターフェイスを要求し、サポートされていない場合はその理由を報告します。 |
Member operators
Operator | Description |
---|---|
IUnknown::operator bool | Checks whether or not the IUnknown object is referencing an interface. |
IUnknown::operator= (代入演算子) | Assigns a value to the IUnknown object. |
Free functions
Function | Description |
---|---|
attach_abi function | Attaches an IUnknown object to a raw pointer that owns a reference to its target; an additional reference is not added. |
copy_from_abi function | Copies to an IUnknown object from another pointer. 現在参照されているインターフェイスまたはオブジェクトの参照カウントをデクリメントし、生ポインター パラメーターをコピーして、そのパラメーターが指すインターフェイスまたはオブジェクトの有効期間の管理を開始します。 |
copy_to_abi function | Copies to another pointer from an IUnknown object. 現在参照されているインターフェイスまたはオブジェクトの参照カウントをインクリメントし、そのインターフェイスまたはオブジェクトのメモリ アドレスをパラメーターにコピーします。 |
detach_abi function | Detaches from the raw IUnknown interface without decrementing the reference count, perhaps to return it to a caller. |
get_abi function | Returns the underlying raw IUnknown interface pointer should you need to pass it to a function. |
get_unknown function | A helper function that returns the address of the underlying raw IUnknown interface of an object of a projected type. |
put_abi function | Returns the address of the underlying raw IUnknown interface pointer as a pointer to a pointer to void; this function helps you call methods (such as COM methods) that return references as out parameters via a pointer to a pointer to void. |
swap function | Swaps the contents of the two IUnknown parameters so that they point at one another's target. |
Free operators
Function | Description |
---|---|
operator!= (不等式演算子) | 2 つのパラメーターが異なるターゲットを参照しているかどうかを示す値を返します。 |
operator< (より小さい演算子) | 最初のパラメーターのターゲットが 2 番目のパラメーターのターゲットよりもメモリ内で前に発生するかどうかを示す値を返します。 |
operator<= (より小さいまたは等しい演算子) | 1 つ目のパラメーターのターゲットが、2 番目のパラメーターのターゲットよりも前のメモリ内で発生するか、または 2 番目のパラメーターと同じ場所にあるかを示す値を返します。 |
operator== (等価演算子) | 2 つのパラメーターが同じインターフェイスまたはオブジェクトを参照しているかどうかを示す値を返します。 |
演算子> (より大きい演算子) | 1 番目のパラメーターのターゲットが、2 番目のパラメーターのターゲットよりも後でメモリ内で発生するかどうかを示す値を返します。 |
operator>= (より大きいまたは等しい演算子) | 1 番目のパラメーターのターゲットが、2 番目のパラメーターのターゲットよりも後で発生するか、2 番目のパラメーターと同じ場所に配置されるかを示す値を返します。 |
IUnknown::IUnknown constructor
Initializes a new instance of the IUnknown struct, optionally with a copy or move of the input data.
Syntax
IUnknown() noexcept;
IUnknown(std::nullptr_t) noexcept;
IUnknown(winrt::Windows::Foundation::IUnknown const& other) noexcept;
IUnknown(winrt::Windows::Foundation::IUnknown&& other) noexcept;
Parameters
other
Another IUnknown that initializes the IUnknown object.
IUnknown::as function
指定したインターフェイスを IUnknown
から要求します。 インターフェイスがサポートされていない場合にスローします。 インターフェイスがサポートされると予想される場合は、このメソッドを使用します。
Syntax
template <typename To> auto as() const;
template <typename To> void as(To& to) const;
Template parameters
typename To
要求されたインターフェイスを記述する型。
この型には、C++/WinRT インターフェイス名または C++/WinRT ランタイム クラス名を指定できます。
auto
戻り値のオーバーロードの場合、この型は従来の COM インターフェイスにすることもできます。
void
を返すオーバーロードの場合、I
が従来の COM インターフェイスであるcom_ptr<I>
することもできます。
Parameters
to
要求されたインターフェイスを受け取る値への参照。
Return value
auto
返されるオーバーロードは、要求されたインターフェイスを C++/WinRT インターフェイスまたはランタイム クラス名の場合は To
の形式で返し、To
が従来の COM インターフェイスの場合は com_ptr<To>
の形式で返します。
IUnknown
がnull
の場合、auto
戻りオーバーロードはnull
を返し、void
戻りオーバーロードはto
をnull
に設定します。
IUnknown
がnull
でないが、インターフェイスを取得できない場合、メソッドはスローします。
IUnknown::try_as function
指定したインターフェイスを IUnknown
から要求します。 インターフェイスがサポートされていない場合は、 null
を生成します。
Syntax
template <typename To> auto try_as() const noexcept;
template <typename To> bool try_as(To& to) const noexcept;
Template parameters
typename To
要求されたインターフェイスを記述する型。
この型には、C++/WinRT インターフェイス名または C++/WinRT ランタイム クラス名を指定できます。
auto
戻り値のオーバーロードの場合、この型は従来の COM インターフェイスにすることもできます。
bool
を返すオーバーロードの場合、I
が従来の COM インターフェイスであるcom_ptr<I>
することもできます。
Parameters
to
要求されたインターフェイスを受け取る値への参照。
Return value
auto
返されるオーバーロードは、要求されたインターフェイスを C++/WinRT インターフェイスまたはランタイム クラス名の場合は To
の形式で返し、To
が従来の COM インターフェイスの場合は com_ptr<To>
の形式で返します。
IUnknown
がnull
されている場合、またはインターフェイスを取得できない場合、auto
返されるオーバーロードはnull
を返し、bool
戻りオーバーロードはto
をnull
に設定します。
オーバーロードを返すbool
は、to
で返される値がnull
でない場合はtrue
を返し、null
の場合はfalse
します。
IUnknown::try_as_with_reason function
サポートされている場合は要求されたインターフェイスを返し、サポートされていない場合は理由を報告します。
Syntax
template <typename To> auto try_as_with_reason(winrt::hresult& reason) const noexcept;
Template parameters
typename To
要求されたインターフェイスを記述する型。
この型には、C++/WinRT インターフェイス名、C++/WinRT ランタイム クラス名、または従来の COM インターフェイスを指定できます。
Parameters
reason
クエリの結果を記述する winrt::hresult
を受け取ります。
Return value
要求されたインターフェイスを C++/WinRT インターフェイスまたはランタイム クラス名の場合は To
の形式で返し、To
が従来の COM インターフェイスの場合は com_ptr<To>
の形式で返します。
IUnknown
がnull
されている場合、またはインターフェイスを取得できない場合、メソッドはnull
を返します。
Remarks
このメソッドは、C++/WinRT バージョン 2.0.250303.1 以降で使用できます。
IUnknown
がnull
の場合、メソッドはnull
を返し、reason
をS_OK
に設定します。
IUnknown
がnull
でない場合、メソッドはクエリの結果を返し、reason
はクエリによって生成されたwinrt::hresult
を受け取ります。
IUnknown::operator bool
Checks whether or not the IUnknown object is referencing an interface. If the IUnknown object is not referencing an interface, then it is logically null; otherwise it is logically not null.
Syntax
explicit operator bool() const noexcept;
Return value
true
if the IUnknown object is referencing an interface (logically not null), otherwise false
(logically null).
IUnknown::operator= (代入演算子)
Assigns a value to the IUnknown object.
Syntax
winrt::Windows::Foundation::IUnknown& operator=(winrt::Windows::Foundation::IUnknown const& other) noexcept;
winrt::Windows::Foundation::IUnknown& operator=(winrt::Windows::Foundation::IUnknown&& other) noexcept;
winrt::Windows::Foundation::IUnknown& operator=(std::nullptr_t) noexcept;
Parameters
other
An IUnknown value to assign to the IUnknown object, either by copy or by move.
Return value
A reference to the IUnknown object.
attach_abi function
Attaches an IUnknown object to a raw pointer that owns a reference to its target; an additional reference is not added. 必要に応じて、この関数を使用して参照を結合できます。
Syntax
void attach_abi(winrt::Windows::Foundation::IUnknown& object, void* value) noexcept;
Parameters
object
An IUnknown value to operate on.
value
ターゲットへの参照を所有する生ポインター。
copy_from_abi function
Copies to an IUnknown object from another pointer. 現在参照されているインターフェイスまたはオブジェクトの参照カウントをデクリメントし、生ポインター パラメーターをコピーして、そのパラメーターが指すインターフェイスまたはオブジェクトの有効期間の管理を開始します。
Syntax
void copy_from_abi(winrt::Windows::Foundation::IUnknown& object, void* value) noexcept;
Parameters
object
An IUnknown value to operate on.
value
A raw pointer to a target whose lifetime should be managed by the IUnknown object.
copy_to_abi function
Copies to another pointer from an IUnknown object. 現在参照されているインターフェイスまたはオブジェクトの参照カウントをインクリメントし、そのインターフェイスまたはオブジェクトのメモリ アドレスをパラメーターにコピーします。 This function lets you hand out a reference to the same interface without calling QueryInterface.
Syntax
void copy_to_abi(winrt::Windows::Foundation::IUnknown const& object, void*& value) noexcept;
Parameters
object
An IUnknown value to operate on.
value
A raw pointer reference; via which to copy the pointer to the IUnknown object's target.
detach_abi function
Detaches an IUnknown object from its raw IUnknown interface without decrementing the reference count, perhaps to return it to a caller.
Syntax
void* detach_abi(winrt::Windows::Foundation::IUnknown& object) noexcept;
void* detach_abi(winrt::Windows::Foundation::IUnknown&& object) noexcept;
Parameters
object
An IUnknown value to operate on.
Return value
A pointer to the raw IUnknown interface referenced by the IUnknown object.
get_abi function
Returns the underlying raw IUnknown interface pointer should you need to pass it to a function. You may call AddRef, Release, or QueryInterface on the returned pointer.
Syntax
void* get_abi(winrt::Windows::Foundation::IUnknown const& object) noexcept;
Parameters
object
An IUnknown value to operate on.
Return value
A pointer to the raw IUnknown interface referenced by the IUnknown object.
operator!= (等しくない演算子)
2 つのパラメーターが異なるターゲットを参照しているかどうかを示す値を返します。
Syntax
bool operator!=(winrt::Windows::Foundation::IUnknown const& left, winrt::Windows::Foundation::IUnknown const& right) noexcept;
Parameters
left
right
An IUnknown value whose target's memory address to compare with that of the other parameter.
Return value
true
2 つのパラメーターが異なるターゲットを指している場合は、それ以外の場合は false
。
演算子< (より小さい演算子)
最初のパラメーターのターゲットが 2 番目のパラメーターのターゲットよりもメモリ内で前に発生するかどうかを示す値を返します。
Syntax
bool operator<(winrt::Windows::Foundation::IUnknown const& left, winrt::Windows::Foundation::IUnknown const& right) noexcept;
Parameters
left
right
An IUnknown value whose target's memory address to compare with that of the other parameter.
Return value
true
最初のパラメータのターゲットのメモリアドレスが2番目のパラメータのメモリアドレスよりも小さい場合は、それ以外の場合は false
。
operator<= (より小さいまたは等しい演算子)
1 つ目のパラメーターのターゲットが、2 番目のパラメーターのターゲットよりも前のメモリ内で発生するか、または 2 番目のパラメーターと同じ場所にあるかを示す値を返します。
Syntax
bool operator<=(winrt::Windows::Foundation::IUnknown const& left, winrt::Windows::Foundation::IUnknown const& right) noexcept;
Parameters
left
right
An IUnknown value whose target's memory address to compare with that of the other parameter.
Return value
true
最初のパラメーターのターゲットのメモリアドレスが2番目のパラメーターのメモリアドレス以下である場合、それ以外の場合は false
。
operator== (等値演算子)
2 つのパラメーターが同じインターフェイスまたはオブジェクトを参照しているかどうかを示す値を返します。
Syntax
bool operator==(winrt::Windows::Foundation::IUnknown const& left, winrt::Windows::Foundation::IUnknown const& right) noexcept;
Parameters
left
right
An IUnknown value whose target's memory address to compare with that of the other parameter.
Return value
true
2 つのパラメーターが同じターゲットを指している場合は、それ以外の場合は false
。
演算子> (より大きい演算子)
1 番目のパラメーターのターゲットが、2 番目のパラメーターのターゲットよりも後でメモリ内で発生するかどうかを示す値を返します。
Syntax
bool operator>(winrt::Windows::Foundation::IUnknown const& left, winrt::Windows::Foundation::IUnknown const& right) noexcept;
Parameters
left
right
An IUnknown value whose target's memory address to compare with that of the other parameter.
Return value
true
最初のパラメータのターゲットのメモリアドレスが2番目のパラメータのメモリアドレスより大きい場合は、それ以外の場合は false
。
operator>= (より大きいまたは等しい演算子)
1 番目のパラメーターのターゲットが、2 番目のパラメーターのターゲットよりも後で発生するか、2 番目のパラメーターと同じ場所に配置されるかを示す値を返します。
Syntax
bool operator>=(winrt::Windows::Foundation::IUnknown const& left, winrt::Windows::Foundation::IUnknown const& right) noexcept;
Parameters
left
right
An IUnknown value whose target's memory address to compare with that of the other parameter.
Return value
true
最初のパラメーターのターゲットのメモリアドレスが2番目のパラメーターのメモリアドレス以上の場合は、それ以外の場合は false
。
put_abi function
Returns the address of the underlying raw IUnknown interface pointer as a pointer to a pointer to void; this function helps you call methods (such as COM methods) that return references as out parameters via a pointer to a pointer to void.
Syntax
void** put_abi(winrt::Windows::Foundation::IUnknown& object) noexcept;
Parameters
object
An IUnknown value to operate on.
Return value
The address of the underlying raw IUnknown interface pointer.
swap function
Swaps the contents of the two IUnknown parameters so that they point at one another's target.
Syntax
void swap(winrt::Windows::Foundation::IUnknown& left, winrt::Windows::Foundation::IUnknown& right) noexcept;
Parameters
left
right
An IUnknown value whose pointer to mutually swap with that of the other parameter.