protected override LoadLibraryResult LoadLibrary(string path) { LoadLibraryResult result; // Disable the error dialog that LoadLibrary shows if it cannot find a DLL dependency. using (new DisableLoadLibraryErrorDialog()) { IntPtr handle = NativeMethods.LoadLibraryW(path); if (handle != IntPtr.Zero) { result = new LoadLibraryResult(handle); } else { int lastError = Marshal.GetLastWin32Error(); result = new LoadLibraryResult(new Win32Exception(lastError)); } } return(result); }
public IntPtr LoadNativeLibrary() { IntPtr handle = IntPtr.Zero; foreach (string path in LibrarySearchPaths) { if (File.Exists(path)) { LoadLibraryResult result = LoadLibrary(path); if (result.Handle != IntPtr.Zero) { handle = result.Handle; break; } else { throw new GmicException($"Unable to the gmic-sharp native library from { path }", result.Error); } } } return(handle); }