Marshal.GetComInterfaceForObject メソッド

定義

オブジェクトのインターフェイスを表すインターフェイス ポインターを返します。

オーバーロード

GetComInterfaceForObject(Object, Type)
互換性のために残されています。

指定したオブジェクトの指定したインターフェイスを表す IUnknown インターフェイスへのポインターを返します。 カスタム クエリ インターフェイス アクセスは既定で有効になっています。

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)
互換性のために残されています。

指定したオブジェクトの指定したインターフェイスを表す IUnknown インターフェイスへのポインターを返します。 カスタム クエリ インターフェイス アクセスは、指定したカスタマイズ モードで制御されます。

GetComInterfaceForObject<T,TInterface>(T)

[.NET Framework 4.5.1 以降のバージョンでサポート]

指定した型のオブジェクトの指定したインターフェイスを表す IUnknown インターフェイスへのポインターを返します。 カスタム クエリ インターフェイス アクセスは既定で有効になっています。

GetComInterfaceForObject(Object, Type)

注意事項

GetComInterfaceForObject(Object, Type) may be unavailable in future releases. Instead, use GetComInterfaceForObject<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296509

指定したオブジェクトの指定したインターフェイスを表す IUnknown インターフェイスへのポインターを返します。 カスタム クエリ インターフェイス アクセスは既定で有効になっています。

public:
 static IntPtr GetComInterfaceForObject(System::Object ^ o, Type ^ T);
[System.Obsolete("GetComInterfaceForObject(Object, Type) may be unavailable in future releases. Instead, use GetComInterfaceForObject<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296509")]
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject (object o, Type T);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject (object o, Type T);
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject (object o, Type T);
public static IntPtr GetComInterfaceForObject (object o, Type T);
[<System.Obsolete("GetComInterfaceForObject(Object, Type) may be unavailable in future releases. Instead, use GetComInterfaceForObject<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296509")>]
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type -> nativeint
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetComInterfaceForObject : obj * Type -> nativeint
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type -> nativeint
static member GetComInterfaceForObject : obj * Type -> nativeint
Public Shared Function GetComInterfaceForObject (o As Object, T As Type) As IntPtr

パラメーター

o
Object

インターフェイスを提供するオブジェクト。

T
Type

要求されるインターフェイスの型。

戻り値

IntPtr

nativeint

オブジェクトの指定したインターフェイスを表すインターフェイス ポインター。

属性

例外

T パラメーターがインターフェイスではありません。

または

型が COM から参照できません。

または

T パラメーターがジェネリック型定義です。

o パラメーターが要求されたインターフェイスをサポートしていません。

o パラメーターが null です。

または

T パラメーターが null です。

注釈

このメソッドは、指定したオブジェクトで要求されたインターフェイスを表すインターフェイス ポインターを返します。 インターフェイス ポインターが渡されることを期待するアンマネージ メソッドがある場合は、特に便利です。 このメソッドを使用してオブジェクトを呼び出すと、ポインターが返される前に、インターフェイス ポインターで参照カウントがインクリメントされます。 ポインターが終了したら、常に参照カウントを減らすために使用 Marshal.Release します。 生の COM インターフェイス ポインターを使用する場合は、COM によって定義された規則に従う必要があります。

GetComInterfaceForObject(Object, Type) は、COM オブジェクト パラメーターを型として IntPtr 公開するメソッドを呼び出す場合や、カスタム マーシャリングを使用する場合に便利です。 あまり一般的ではありませんが、マネージド オブジェクトでこのメソッドを使用して、オブジェクトの COM 呼び出し可能ラッパーへのポインターを取得できます。 たとえば、COM にエクスポートされるマネージド オブジェクトで使用 GetComInterfaceForObject(Object, Type) して、インターフェイス ポインター System.Runtime.InteropServices.UCOMIConnectionPointContainerを取得できます。 クラス インターフェイスには、2 番目のパラメーター (t) に渡す対応する型がないため、クラス インターフェイスへのポインターを取得できません。 代わりに、COM 呼び出し可能ラッパーの既定のインターフェイス (通常は自動ディスパッチ クラス インターフェイス) でメンバーを呼び出すために使用 Marshal.GetIDispatchForObject します。

メソッド オーバーロードを GetComInterfaceForObject(Object, Type) 使用すると、既定でクエリ インターフェイスをカスタマイズできます。 クエリ インターフェイスのカスタマイズを適用するかどうかを指定するには、メソッド オーバーロードを GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) 使用します。

詳細については、 COM 呼び出し可能ラッパーとランタイム呼び出可能ラッパー に関する記事を参照してください。

こちらもご覧ください

適用対象

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)

注意事項

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.

指定したオブジェクトの指定したインターフェイスを表す IUnknown インターフェイスへのポインターを返します。 カスタム クエリ インターフェイス アクセスは、指定したカスタマイズ モードで制御されます。

public:
 static IntPtr GetComInterfaceForObject(System::Object ^ o, Type ^ T, System::Runtime::InteropServices::CustomQueryInterfaceMode mode);
[System.Obsolete("GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject (object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject (object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject (object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
public static IntPtr GetComInterfaceForObject (object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[<System.Obsolete("GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
Public Shared Function GetComInterfaceForObject (o As Object, T As Type, mode As CustomQueryInterfaceMode) As IntPtr

パラメーター

o
Object

インターフェイスを提供するオブジェクト。

T
Type

要求されるインターフェイスの型。

mode
CustomQueryInterfaceMode

ICustomQueryInterface によって提供される IUnknown::QueryInterface カスタマイズを適用するかどうかを示す列挙値のいずれか。

戻り値

IntPtr

nativeint

オブジェクトのインターフェイスを表すインターフェイス ポインター。

属性

例外

T パラメーターがインターフェイスではありません。

または

型が COM から参照できません。

または

T パラメーターがジェネリック型定義です。

オブジェクト o が要求されたインターフェイスをサポートしていません。

o パラメーターが null です。

または

T パラメーターが null です。

注釈

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) では、クエリ インターフェイスのカスタマイズを適用するかどうかを指定できます。 既定では、オーバーロードを GetComInterfaceForObject(Object, Type) 使用してクエリ インターフェイスのカスタマイズを適用します。

適用対象

GetComInterfaceForObject<T,TInterface>(T)

[.NET Framework 4.5.1 以降のバージョンでサポート]

指定した型のオブジェクトの指定したインターフェイスを表す IUnknown インターフェイスへのポインターを返します。 カスタム クエリ インターフェイス アクセスは既定で有効になっています。

public:
generic <typename T, typename TInterface>
 static IntPtr GetComInterfaceForObject(T o);
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject<T,TInterface> (T o);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject<T,TInterface> (T o);
public static IntPtr GetComInterfaceForObject<T,TInterface> (T o);
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : 'T -> nativeint
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetComInterfaceForObject : 'T -> nativeint
static member GetComInterfaceForObject : 'T -> nativeint
Public Shared Function GetComInterfaceForObject(Of T, TInterface) (o As T) As IntPtr

型パラメーター

T

o の型。

TInterface

返すインターフェイスの型。

パラメーター

o
T

インターフェイスを提供するオブジェクト。

戻り値

IntPtr

nativeint

TInterface インターフェイスを表すインターフェイス ポインター。

属性

例外

TInterface パラメーターがインターフェイスではありません。

または

型が COM から参照できません。

または

T パラメーターがオープン ジェネリック型です。

o パラメーターが TInterface インターフェイスをサポートしていません。

o パラメーターが null です。

注釈

このメソッドは、指定したオブジェクトのインターフェイスを TInterface 表すインターフェイス ポインターを返します。 インターフェイス ポインターが渡されることを想定したアンマネージ メソッドがある場合は、特に便利です。 このメソッドを使用してオブジェクトを呼び出すと、ポインターが返される前に、インターフェイス ポインターで参照カウントがインクリメントされます。 ポインターが Marshal.Release 終了したら、常にメソッドを使用して参照カウントをデクリメントします。 生の COM インターフェイス ポインターを使用する場合は、COM によって定義された規則に従う必要があります。

GetComInterfaceForObject<T,TInterface>(T) は、COM オブジェクト パラメーターを型として IntPtr 公開するメソッドを呼び出す場合や、カスタム マーシャリングを使用する場合に便利です。 マネージド オブジェクトでこのメソッドを使用して、オブジェクトの COM 呼び出し可能ラッパーへのポインターを取得することもできますが、これはあまり一般的ではありません。 たとえば、COM にエクスポートされるマネージド オブジェクトで使用 GetComInterfaceForObject<T,TInterface>(T) して、インターフェイス ポインター System.Runtime.InteropServices.UCOMIConnectionPointContainerを取得できます。

メソッドの GetComInterfaceForObject<T,TInterface>(T) オーバーロードでは、既定でクエリ インターフェイスをカスタマイズできます。 クエリ インターフェイスのカスタマイズを適用するかどうかを指定するには、メソッドのオーバーロードを GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) 使用します。

詳細については、 COM 呼び出し可能ラッパーとランタイム呼び出可能ラッパー に関する記事を参照してください。

適用対象