Marshal.GetDelegateForFunctionPointer 方法

定义

重载

GetDelegateForFunctionPointer(IntPtr, Type)
已过时.

将非托管函数指针转换为委托。

GetDelegateForFunctionPointer<TDelegate>(IntPtr)

将非托管函数指针转换为指定类型的委托。

GetDelegateForFunctionPointer(IntPtr, Type)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
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

将非托管函数指针转换为委托。

public:
 static Delegate ^ GetDelegateForFunctionPointer(IntPtr ptr, Type ^ t);
[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);
public static Delegate GetDelegateForFunctionPointer (IntPtr ptr, Type t);
[System.Security.SecurityCritical]
public static Delegate GetDelegateForFunctionPointer (IntPtr ptr, Type t);
[<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>]
static member GetDelegateForFunctionPointer : nativeint * Type -> Delegate
static member GetDelegateForFunctionPointer : nativeint * Type -> Delegate
[<System.Security.SecurityCritical>]
static member GetDelegateForFunctionPointer : nativeint * Type -> Delegate
Public Shared Function GetDelegateForFunctionPointer (ptr As IntPtr, t As Type) As Delegate

参数

ptr
IntPtr

nativeint

要转换的非托管函数指针。

t
Type

要返回的委托的类型。

返回

可转换为适当的委托类型的委托实例。

属性

例外

t 参数不是委托或泛型。

ptr 参数为 null

- 或 -

t 参数为 null

注解

可以使用 GetDelegateForFunctionPointerGetFunctionPointerForDelegate 方法在两个方向封送委托。 使用 GetDelegateForFunctionPointer时, ptr 将作为 System.IntPtr导入。 System.IntPtr可以通过调用 GetFunctionPointerForDelegate 来获取托管委托的 并将其作为参数传递;然后可以从非托管方法内部调用它。 请注意,参数封送处理程序还可以封送.NET Framework 2.0 及更高版本中指向委托的函数指针。

ptr 转换为使用 默认平台调用约定调用非托管方法的委托。 可以通过将 应用于 UnmanagedFunctionPointerAttribute 委托来设置调用约定。

方法 GetDelegateForFunctionPointer 具有以下限制:

  • 互操作方案中不支持泛型。

  • 只能将此方法用于纯非托管函数指针。

  • 不能将此方法用于通过 C++ 获取的函数指针。

适用于

GetDelegateForFunctionPointer<TDelegate>(IntPtr)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

将非托管函数指针转换为指定类型的委托。

public:
generic <typename TDelegate>
 static TDelegate GetDelegateForFunctionPointer(IntPtr ptr);
[System.Security.SecurityCritical]
public static TDelegate GetDelegateForFunctionPointer<TDelegate> (IntPtr ptr);
public static TDelegate GetDelegateForFunctionPointer<TDelegate> (IntPtr ptr);
[<System.Security.SecurityCritical>]
static member GetDelegateForFunctionPointer : nativeint -> 'Delegate
static member GetDelegateForFunctionPointer : nativeint -> 'Delegate
Public Shared Function GetDelegateForFunctionPointer(Of TDelegate) (ptr As IntPtr) As TDelegate

类型参数

TDelegate

要返回的委托的类型。

参数

ptr
IntPtr

nativeint

要转换的非托管函数指针。

返回

TDelegate

指定委托类型的实例。

属性

例外

TDelegate 泛型参数不是代理,或者它是开放式泛型类型。

ptr 参数为 null

注解

可以使用 GetDelegateForFunctionPointer<TDelegate>(IntPtr)GetFunctionPointerForDelegate<TDelegate>(TDelegate) 方法在两个方向封送委托。

ptr 转换为使用 默认平台调用约定调用非托管方法的委托。 可以通过将 应用于 UnmanagedFunctionPointerAttribute 委托来设置调用约定。

方法 GetDelegateForFunctionPointer<TDelegate>(IntPtr) 具有以下限制:

  • 互操作方案中不支持泛型。

  • 只能将此方法用于纯非托管函数指针。

  • 不能将此方法用于通过 C++ 获取的函数指针。

适用于