示例#1
0
        public static void Initialize(IntPtr libraryHandle, LibraryLoader loader)
        {
            if (libraryHandle == IntPtr.Zero)
            {
                ExceptionUtil.ThrowArgumentNullException(nameof(libraryHandle));
            }

            if (loader is null)
            {
                ExceptionUtil.ThrowArgumentNullException(nameof(loader));
            }

            if (instance == null)
            {
                instance = new GmicNativeMethods(libraryHandle, loader);
            }
        }
示例#2
0
        private static void LoadNativeLibrary()
        {
            // Exit early if the library has already been loaded.
            if (nativeLibraryHandle != IntPtr.Zero)
            {
                return;
            }

            LibraryLoader loader;

            if (PlatformHelper.IsWindows)
            {
                loader = new WindowsLibraryLoader();
            }
            else if (PlatformHelper.IsLinux)
            {
                loader = new LinuxLibraryLoader();
            }
            else if (PlatformHelper.IsMac)
            {
                loader = new MacLibraryLoader();
            }
            else if (PlatformHelper.IsBsd)
            {
                loader = new BsdLibraryLoader();
            }
            else
            {
                throw new GmicException("The gmic-sharp native library is not supported on the current platform.");
            }

            nativeLibraryHandle = loader.LoadNativeLibrary();

            if (nativeLibraryHandle == IntPtr.Zero)
            {
                throw new GmicException($"The gmic-sharp native library was not found. SearchPaths={ loader.LibrarySearchPaths.Aggregate((a, b) => a + ";" + b) }");
            }

            GmicNativeMethods.Initialize(nativeLibraryHandle, loader);
        }