NativeLibrary.Load 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| Load(String) |
提供一個簡單的 API,用來載入一個原生函式庫,該函式庫會包裝作業系統載入器並使用預設旗標。 |
| Load(String, Assembly, Nullable<DllImportSearchPath>) |
提供高階 API 以載入原生函式庫。 |
Load(String)
提供一個簡單的 API,用來載入一個原生函式庫,該函式庫會包裝作業系統載入器並使用預設旗標。
public:
static IntPtr Load(System::String ^ libraryPath);
public static IntPtr Load(string libraryPath);
static member Load : string -> nativeint
Public Shared Function Load (libraryPath As String) As IntPtr
參數
- libraryPath
- String
要載入的原生函式庫名稱。
傳回
nativeint
作業系統的 Handle 用於載入的原生函式庫。
例外狀況
libraryPath 是 null。
找不到圖書館。
圖書館不合格。
適用於
Load(String, Assembly, Nullable<DllImportSearchPath>)
提供高階 API 以載入原生函式庫。
public:
static IntPtr Load(System::String ^ libraryName, System::Reflection::Assembly ^ assembly, Nullable<System::Runtime::InteropServices::DllImportSearchPath> searchPath);
public static IntPtr Load(string libraryName, System.Reflection.Assembly assembly, System.Runtime.InteropServices.DllImportSearchPath? searchPath);
static member Load : string * System.Reflection.Assembly * Nullable<System.Runtime.InteropServices.DllImportSearchPath> -> nativeint
Public Shared Function Load (libraryName As String, assembly As Assembly, searchPath As Nullable(Of DllImportSearchPath)) As IntPtr
參數
- libraryName
- String
要載入的原生函式庫名稱。
- assembly
- Assembly
組裝時載入原生函式庫。
- searchPath
- Nullable<DllImportSearchPath>
搜尋路徑。
傳回
nativeint
作業系統的函式庫代稱。
例外狀況
libraryName 或 assembly 為 null。
assembly 不是 RuntimeAssembly。
找不到圖書館。
圖書館不合格。
備註
給定函式庫名稱後,此方法會根據執行時設定、輸入參數及呼叫組合語言的屬性搜尋特定路徑。 若參數 searchPath 非空,則使用此列舉中的旗標。 否則,若有呼叫組件上指定的 DefaultDllImportSearchPathsAttribute 旗標,則會使用。 此方法不會呼叫註冊於方法 SetDllImportResolver(Assembly, DllImportResolver) 的解析器。 從 .NET 5 開始,此方法會觸發 AssemblyLoadContext.LoadUnmanagedDll 方法及 AssemblyLoadContext.ResolvingUnmanagedDll 事件。