コード例 #1
0
        /// <summary>
        /// Attempts to load a native library with the specified path resolver.
        /// </summary>
        private IntPtr LoadWithResolver(String name, PathResolver pathResolver)
        {
            var targets = pathResolver.EnumeratePossibleLibraryLoadTargets(name);

            foreach (var target in targets)
            {
                if (!Path.IsPathRooted(target) || File.Exists(target))
                {
                    var ret = CoreLoadNativeLibrary(target);
                    if (ret != IntPtr.Zero)
                    {
                        return(ret);
                    }
                }
            }
            return(IntPtr.Zero);
        }
コード例 #2
0
        /// <summary>
        /// Loads a native library by name and return an operating system handle which represents it.
        /// </summary>
        /// <param name="names">An ordered collection of library names. Each name is tried in
        /// turn until the library is successfully loaded.</param>
        /// <param name="pathResolver">A <see cref="PathResolver"/> instance which specifies
        /// the algorithm for resolving library paths from names.</param>
        /// <returns>An <see cref="IntPtr"/> which represents the native library's handle.</returns>
        public IntPtr LoadNativeLibrary(IEnumerable <String> names, PathResolver pathResolver)
        {
            Contract.Require(names, nameof(names));

            var ret = IntPtr.Zero;

            foreach (var name in names)
            {
                ret = LoadWithResolver(name, pathResolver);
                if (ret != IntPtr.Zero)
                {
                    break;
                }
            }

            if (ret == IntPtr.Zero)
            {
                throw new FileNotFoundException(CoreStrings.CouldNotLoadLibraryFromNames.Format(String.Join(", ", names)));
            }

            return(ret);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NativeLibrary"/> class.
 /// </summary>
 /// <param name="names">An ordered collection of library names. Each name is tried in
 /// turn until the library is successfully loaded.</param>
 /// <param name="loader">The <see cref="LibraryLoader"/> which is used to load the library
 /// and retrieve function pointers.</param>
 /// <param name="pathResolver">A <see cref="PathResolver"/> instance which determines the algorithm
 /// for resolving library paths from library names.</param>
 public NativeLibrary(IEnumerable <String> names, LibraryLoader loader, PathResolver pathResolver)
 {
     this.loader = loader;
     this.Handle = loader.LoadNativeLibrary(names, pathResolver);
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NativeLibrary"/> class.
 /// </summary>
 /// <param name="name">The name of the library to load.</param>
 /// <param name="loader">The <see cref="LibraryLoader"/> which is used to load the library
 /// and retrieve function pointers.</param>
 /// <param name="pathResolver">A <see cref="PathResolver"/> instance which determines the algorithm
 /// for resolving library paths from library names.</param>
 public NativeLibrary(String name, LibraryLoader loader, PathResolver pathResolver)
 {
     this.loader = loader;
     this.Handle = loader.LoadNativeLibrary(name, pathResolver);
 }