/// <summary> /// Load library /// </summary> internal static IntPtr LoadLibrary(string libraryPath, out string errorMsg) { if (IsWindows) { errorMsg = null; //var handle = GetWin32ModuleHandle(libraryPath); //if (handle != IntPtr.Zero) return handle; var handle = WindowsLoader.LoadLibrary(libraryPath); if (handle == IntPtr.Zero) { throw new System.ComponentModel.Win32Exception($"failed to load library {libraryPath}"); } return(handle); } if (IsLinux) { if (IsNetCore) { return(LoadLibraryPosix(CoreCLRLoader.dlopen, CoreCLRLoader.dlerror, libraryPath, out errorMsg)); } return(LoadLibraryPosix(LinuxLoader.dlopen, LinuxLoader.dlerror, libraryPath, out errorMsg)); } if (IsMacOSX) { return(LoadLibraryPosix(MacOSXLoader.dlopen, MacOSXLoader.dlerror, libraryPath, out errorMsg)); } throw new InvalidOperationException("Unsupported platform."); }
/// <summary> /// Load library /// </summary> internal static IntPtr LoadLibrary(string libraryPath, out string errorMsg) { if (IsWindows) { errorMsg = null; //var handle = GetWin32ModuleHandle(libraryPath); //if (handle != IntPtr.Zero) return handle; var handle = WindowsLoader.LoadLibrary(libraryPath); if (handle == IntPtr.Zero) { throw new System.ComponentModel.Win32Exception($"failed to load library {libraryPath}"); } return(handle); } throw new InvalidOperationException("Unsupported platform."); }