mirror of
https://github.com/nomic-ai/gpt4all
synced 2024-11-06 09:20:33 +00:00
25 lines
743 B
C#
25 lines
743 B
C#
|
using System.ComponentModel;
|
||
|
using System.Runtime.InteropServices;
|
||
|
|
||
|
namespace Gpt4All.LibraryLoader;
|
||
|
|
||
|
internal class WindowsLibraryLoader : ILibraryLoader
|
||
|
{
|
||
|
public LoadResult OpenLibrary(string? fileName)
|
||
|
{
|
||
|
var loadedLib = LoadLibrary(fileName);
|
||
|
|
||
|
if (loadedLib == IntPtr.Zero)
|
||
|
{
|
||
|
var errorCode = Marshal.GetLastWin32Error();
|
||
|
var errorMessage = new Win32Exception(errorCode).Message;
|
||
|
return LoadResult.Failure(errorMessage);
|
||
|
}
|
||
|
|
||
|
return LoadResult.Success;
|
||
|
}
|
||
|
|
||
|
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Auto)]
|
||
|
private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPWStr)] string? lpFileName);
|
||
|
}
|