Marshal.GetDelegateForFunctionPointer 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
GetDelegateForFunctionPointer(IntPtr, Type) |
已淘汰.
將 Unmanaged 函式指標轉換成委派。 |
GetDelegateForFunctionPointer<TDelegate>(IntPtr) |
將 Unmanaged 函式指標轉換成所指定類型的委派。 |
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
將 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
參數不是委派,或者是泛型。
備註
您可以使用 GetDelegateForFunctionPointer 和 GetFunctionPointerForDelegate 方法來封送處理雙向委派。 使用 GetDelegateForFunctionPointer時, ptr
會匯入為 System.IntPtr。 System.IntPtr您可以藉由呼叫 GetFunctionPointerForDelegate 並傳遞做為參數來取得 Managed 委派的 ,然後可以從 Unmanaged 方法內呼叫它。 請注意,參數封送處理器也可以封送處理 .NET Framework 2.0 和更新版本中委派的函式指標。
ptr
會轉換成使用 預設平臺呼叫慣例叫用 Unmanaged 方法的委派。 您可以將 套用 UnmanagedFunctionPointerAttribute 至委派,以設定呼叫慣例。
方法 GetDelegateForFunctionPointer 具有下列限制:
Interop 案例中不支援泛型。
您只能將這個方法用於純非受控函式指標。
您無法搭配透過 C++ 取得的函式指標使用此方法。
適用於
GetDelegateForFunctionPointer<TDelegate>(IntPtr)
- 來源:
- Marshal.cs
- 來源:
- Marshal.cs
- 來源:
- 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
泛型參數不是委派,否則就是開放式泛型類型。
ptr
參數為 null
。
備註
您可以使用 GetDelegateForFunctionPointer<TDelegate>(IntPtr) 和 GetFunctionPointerForDelegate<TDelegate>(TDelegate) 方法來封送處理雙向委派。
ptr
會轉換成使用 預設平臺呼叫慣例叫用 Unmanaged 方法的委派。 您可以將 套用 UnmanagedFunctionPointerAttribute 至委派,以設定呼叫慣例。
方法 GetDelegateForFunctionPointer<TDelegate>(IntPtr) 具有下列限制:
Interop 案例中不支援泛型。
您只能將這個方法用於純非受控函式指標。
您無法搭配透過 C++ 取得的函式指標使用此方法。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應