Marshal.GetDelegateForFunctionPointer メソッド

定義

オーバーロード

GetDelegateForFunctionPointer(IntPtr, Type)
古い.

アンマネージ関数ポインターをデリゲートに変換します。

GetDelegateForFunctionPointer<TDelegate>(IntPtr)

アンマネージ関数ポインターを指定した型のデリゲートに変換します。

GetDelegateForFunctionPointer(IntPtr, Type)

ソース:
Marshal.cs
ソース:
Marshal.cs
ソース:
Marshal.cs

注意事項

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

アンマネージ関数ポインターをデリゲートに変換します。

C#
[System.Obsolete("GetDelegateForFunctionPointer(IntPtr, Type) may be unavailable in future releases. Instead, use GetDelegateForFunctionPointer<T>(IntPtr). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296521")]
[System.Security.SecurityCritical]
public static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t);
C#
public static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t);
C#
[System.Security.SecurityCritical]
public static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t);

パラメーター

ptr
IntPtr

変換するアンマネージ関数ポインター。

t
Type

返されるデリゲートの型。

戻り値

適切なデリゲート型にキャストできるデリゲート インスタンス。

属性

例外

t パラメーターは、デリゲートでもジェネリックでもありません。

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

または

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

注釈

メソッドと GetFunctionPointerForDelegate メソッドをGetDelegateForFunctionPointer使用して、デリゲートを双方向にマーシャリングできます。 ではGetDelegateForFunctionPointerptr、 は としてSystem.IntPtrインポートされます。 System.IntPtrを呼び出GetFunctionPointerForDelegateしてパラメーターとして渡すことで、マネージド デリゲートの を取得できます。その後、アンマネージ メソッド内から呼び出すことができます。 パラメーター マーシャラーでは、.NET Framework 2.0 以降のバージョンのデリゲートへの関数ポインターをマーシャリングすることもできます。

ptr は、既定のプラットフォーム呼び出し規則を使用してアンマネージ メソッド を呼び出すデリゲートに変換されます。 呼び出し規約を設定するには、 を UnmanagedFunctionPointerAttribute デリゲートに適用します。

GetDelegateForFunctionPointerメソッドには、次の制限があります。

  • ジェネリックは、相互運用シナリオではサポートされていません。

  • このメソッドは、純粋なアンマネージ関数ポインターに対してのみ使用できます。

  • このメソッドは、C++ を介して取得された関数ポインターでは使用できません。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン (廃止)
.NET Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 (Core 1.0)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 2.0, 2.1 (1.2, 1.3, 1.4, 1.5, 1.6)
UWP (10.0)

GetDelegateForFunctionPointer<TDelegate>(IntPtr)

ソース:
Marshal.cs
ソース:
Marshal.cs
ソース:
Marshal.cs

アンマネージ関数ポインターを指定した型のデリゲートに変換します。

C#
[System.Security.SecurityCritical]
public static TDelegate GetDelegateForFunctionPointer<TDelegate>(IntPtr ptr);
C#
public static TDelegate GetDelegateForFunctionPointer<TDelegate>(IntPtr ptr);

型パラメーター

TDelegate

返すデリゲートの型。

パラメーター

ptr
IntPtr

変換するアンマネージ関数ポインター。

戻り値

TDelegate

指定したデリゲート型のインスタンス。

属性

例外

TDelegate ジェネリック パラメーターはデリゲートでない、またはオープン ジェネリック型です。

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

注釈

メソッドと GetFunctionPointerForDelegate<TDelegate>(TDelegate) メソッドをGetDelegateForFunctionPointer<TDelegate>(IntPtr)使用して、デリゲートを双方向にマーシャリングできます。

ptr は、既定のプラットフォーム呼び出し規則を使用してアンマネージ メソッド を呼び出すデリゲートに変換されます。 呼び出し規約を設定するには、 を UnmanagedFunctionPointerAttribute デリゲートに適用します。

GetDelegateForFunctionPointer<TDelegate>(IntPtr)メソッドには、次の制限があります。

  • ジェネリックは、相互運用シナリオではサポートされていません。

  • このメソッドは、純粋なアンマネージ関数ポインターに対してのみ使用できます。

  • このメソッドは、C++ を介して取得された関数ポインターでは使用できません。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0