Marshal.GetDelegateForFunctionPointer 方法

定義

多載

GetDelegateForFunctionPointer(IntPtr, Type)
已淘汰.

將 Unmanaged 函式指標轉換成委派。

GetDelegateForFunctionPointer<TDelegate>(IntPtr)

將 Unmanaged 函式指標轉換成所指定類型的委派。

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

將 Unmanaged 函式指標轉換成委派。

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

要轉換的 Unmanaged 函式指標。

t
Type

要傳回的委派型别。

傳回

委派執行個體,可轉型成適當的委派類型。

屬性

例外狀況

t 參數不是委派,或者是泛型。

ptr 參數為 null

-或-

t 參數為 null

備註

您可以使用 GetDelegateForFunctionPointerGetFunctionPointerForDelegate 方法來封送處理雙向委派。 使用 GetDelegateForFunctionPointer 時, ptr 會匯入為 System.IntPtrSystem.IntPtr可以藉由呼叫 GetFunctionPointerForDelegate 並傳遞做為參數來取得 Managed 委派的 ;然後可從 Unmanaged 方法內呼叫它。 請注意,參數封送處理器也可以封送處理.NET Framework 2.0 和更新版本中委派的函式指標。

ptr 會轉換為使用 預設平臺呼叫慣例叫用 Unmanaged 方法的委派。 您可以藉由將 套用 UnmanagedFunctionPointerAttribute 至委派來設定呼叫慣例。

方法 GetDelegateForFunctionPointer 有下列限制:

  • Interop 案例中不支援泛型。

  • 您只能針對純 Unmanaged 函式指標使用這個方法。

  • 您無法搭配透過 C++ 取得的函式指標使用這個方法。

適用於

GetDelegateForFunctionPointer<TDelegate>(IntPtr)

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

將 Unmanaged 函式指標轉換成所指定類型的委派。

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

要轉換的 Unmanaged 函式指標。

傳回

TDelegate

指定之委派類型的執行個體。

屬性

例外狀況

TDelegate 泛型參數不是委派,否則就是開放式泛型類型。

ptr 參數為 null

備註

您可以使用 GetDelegateForFunctionPointer<TDelegate>(IntPtr)GetFunctionPointerForDelegate<TDelegate>(TDelegate) 方法來封送處理雙向委派。

ptr 會轉換為使用 預設平臺呼叫慣例叫用 Unmanaged 方法的委派。 您可以藉由將 套用 UnmanagedFunctionPointerAttribute 至委派來設定呼叫慣例。

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

  • Interop 案例中不支援泛型。

  • 您只能針對純 Unmanaged 函式指標使用這個方法。

  • 您無法搭配透過 C++ 取得的函式指標使用這個方法。

適用於