Exemplo n.º 1
0
 /// <summary>
 /// Load library
 /// </summary>
 internal static IntPtr LoadLibrary(string libraryPath, out string errorMsg)
 {
     if (IsWindows)
     {
         errorMsg = null;
         //var handle = GetWin32ModuleHandle(libraryPath);
         //if (handle != IntPtr.Zero) return handle;
         var handle = WindowsLoader.LoadLibrary(libraryPath);
         if (handle == IntPtr.Zero)
         {
             throw new System.ComponentModel.Win32Exception($"failed to load library {libraryPath}");
         }
         return(handle);
     }
     if (IsLinux)
     {
         if (IsNetCore)
         {
             return(LoadLibraryPosix(CoreCLRLoader.dlopen, CoreCLRLoader.dlerror, libraryPath, out errorMsg));
         }
         return(LoadLibraryPosix(LinuxLoader.dlopen, LinuxLoader.dlerror, libraryPath, out errorMsg));
     }
     if (IsMacOSX)
     {
         return(LoadLibraryPosix(MacOSXLoader.dlopen, MacOSXLoader.dlerror, libraryPath, out errorMsg));
     }
     throw new InvalidOperationException("Unsupported platform.");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Loads method in the library
        /// </summary>
        /// <param name="symbolName">The methold of the library</param>
        /// <returns>method address</returns>
        private IntPtr LoadSymbol(string symbolName)
        {
            if (IsWindows)
            {
                return(WindowsLoader.GetProcAddress(Handle, symbolName));
            }

            throw new InvalidOperationException("Unsupported platform.");
        }
Exemplo n.º 3
0
        internal static bool FreeLibrary(IntPtr handle)
        {
            string errorMsg = null;

            if (IsWindows)
            {
                return(WindowsLoader.FreeLibrary(handle));
            }

            throw new InvalidOperationException("Unsupported platform.");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load library
        /// </summary>
        internal static IntPtr LoadLibrary(string libraryPath, out string errorMsg)
        {
            if (IsWindows)
            {
                errorMsg = null;
                //var handle = GetWin32ModuleHandle(libraryPath);
                //if (handle != IntPtr.Zero) return handle;
                var handle = WindowsLoader.LoadLibrary(libraryPath);
                if (handle == IntPtr.Zero)
                {
                    throw new System.ComponentModel.Win32Exception($"failed to load library {libraryPath}");
                }
                return(handle);
            }

            throw new InvalidOperationException("Unsupported platform.");
        }
Exemplo n.º 5
0
 /// <summary>
 /// Loads method in the library
 /// </summary>
 /// <param name="symbolName">The methold of the library</param>
 /// <returns>method address</returns>
 private IntPtr LoadSymbol(string symbolName)
 {
     if (IsWindows)
     {
         return(WindowsLoader.GetProcAddress(Handle, symbolName));
     }
     if (IsLinux)
     {
         if (IsNetCore)
         {
             return(CoreCLRLoader.dlsym(Handle, symbolName));
         }
         return(LinuxLoader.dlsym(Handle, symbolName));
     }
     if (IsMacOSX)
     {
         return(MacOSXLoader.dlsym(Handle, symbolName));
     }
     throw new InvalidOperationException("Unsupported platform.");
 }
Exemplo n.º 6
0
        internal static bool FreeLibrary(IntPtr handle)
        {
            string errorMsg = null;

            if (IsWindows)
            {
                return(WindowsLoader.FreeLibrary(handle));
            }
            if (IsLinux)
            {
                if (IsNetCore)
                {
                    return(UnloadLibraryPosix(CoreCLRLoader.dlclose, CoreCLRLoader.dlerror, handle, out errorMsg));
                }
                return(UnloadLibraryPosix(LinuxLoader.dlclose, LinuxLoader.dlerror, handle, out errorMsg));
            }
            if (IsMacOSX)
            {
                return(UnloadLibraryPosix(MacOSXLoader.dlclose, MacOSXLoader.dlerror, handle, out errorMsg));
            }
            throw new InvalidOperationException("Unsupported platform.");
        }