Ejemplo n.º 1
0
        /// <inheritdoc />
        public IntPtr GetAddress(string entryPoint)
        {
            if (entryPoint == null)
            {
                throw new ArgumentNullException(nameof(entryPoint));
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(Kernel32.GetProcAddress(_handle, entryPoint));
            }
            else
            {
                return(LibDL.GetProcAddress(_handle, entryPoint));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the <see cref="NativeLibrary"/> instance.
        /// </summary>
        /// <param name="libraryName">the library name</param>
        public NativeLibrary(string libraryName)
        {
            if (libraryName == null)
            {
                throw new ArgumentNullException(nameof(libraryName));
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                _handle = Kernel32.LoadLibraryEx(libraryName, IntPtr.Zero, 0);
            }
            else
            {
                _handle = LibDL.LoadLibrary(libraryName, LibDL.RTLD_NOW);
            }

            if (_handle == IntPtr.Zero)
            {
                throw new DllNotFoundException($"Failed to load library with name `{libraryName}`.");
            }
        }