NativeLibrary.TryLoad Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
TryLoad(String, IntPtr) |
Provides a simple API for loading a native library and returns a value that indicates whether the operation succeeded. |
TryLoad(String, Assembly, Nullable<DllImportSearchPath>, IntPtr) |
Provides a high-level API that loads a native library and returns a value that indicates whether the operation succeeded. |
- Source:
- NativeLibrary.cs
- Source:
- NativeLibrary.cs
- Source:
- NativeLibrary.cs
Provides a simple API for loading a native library and returns a value that indicates whether the operation succeeded.
public:
static bool TryLoad(System::String ^ libraryPath, [Runtime::InteropServices::Out] IntPtr % handle);
public static bool TryLoad (string libraryPath, out IntPtr handle);
static member TryLoad : string * nativeint -> bool
Public Shared Function TryLoad (libraryPath As String, ByRef handle As IntPtr) As Boolean
Parameters
- libraryPath
- String
The name of the native library to be loaded.
- handle
-
IntPtr
nativeint
When the method returns, the OS handle of the loaded native library.
Returns
true
if the native library was loaded successfully; otherwise, false
.
Exceptions
libraryPath
is null
.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
- Source:
- NativeLibrary.cs
- Source:
- NativeLibrary.cs
- Source:
- NativeLibrary.cs
Provides a high-level API that loads a native library and returns a value that indicates whether the operation succeeded.
public:
static bool TryLoad(System::String ^ libraryName, System::Reflection::Assembly ^ assembly, Nullable<System::Runtime::InteropServices::DllImportSearchPath> searchPath, [Runtime::InteropServices::Out] IntPtr % handle);
public static bool TryLoad (string libraryName, System.Reflection.Assembly assembly, System.Runtime.InteropServices.DllImportSearchPath? searchPath, out IntPtr handle);
static member TryLoad : string * System.Reflection.Assembly * Nullable<System.Runtime.InteropServices.DllImportSearchPath> * nativeint -> bool
Public Shared Function TryLoad (libraryName As String, assembly As Assembly, searchPath As Nullable(Of DllImportSearchPath), ByRef handle As IntPtr) As Boolean
Parameters
- libraryName
- String
The name of the native library to be loaded.
- assembly
- Assembly
The assembly loading the native library.
- searchPath
- Nullable<DllImportSearchPath>
The search path.
- handle
-
IntPtr
nativeint
When the method returns, the OS handle of the loaded native library.
Returns
true
if the native library was loaded successfully; otherwise, false
.
Exceptions
libraryPath
or assembly
is null
.
assembly
is not a RuntimeAssembly
.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: