public static T LoadFunction <T>(IntPtr library, string function)
        {
            var ret = IntPtr.Zero;

            if (CurrentPlatform.OS == OS.Windows)
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (CurrentPlatform.OS == OS.MacOSX)
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            if (ret == IntPtr.Zero)
            {
                return(default(T));
            }

            // TODO: Use the function bellow once Protobuild gets axed
            // requires .NET Framework 4.5.1 and its useful for corert
            // return Marshal.GetDelegateForFunctionPointer<T>(ret);

            return((T)(object)Marshal.GetDelegateForFunctionPointer(ret, typeof(T)));
        }
        public static T LoadFunction <T> (IntPtr library, string function, bool throwIfNotFound = true)
        {
            var ret = IntPtr.Zero;

            if (CurrentPlatform.OS == OS.Windows)
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (CurrentPlatform.OS == OS.MacOSX)
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            if (ret == IntPtr.Zero)
            {
                if (throwIfNotFound)
                {
                    throw new EntryPointNotFoundException(function);
                }

                return(default(T));
            }

#if NETSTANDARD
            return(Marshal.GetDelegateForFunctionPointer <T> (ret));
#else
            return(( T )( object )Marshal.GetDelegateForFunctionPointer(ret, typeof(T)));
#endif
        }
Example #3
0
        public static T LoadFunction <T>(IntPtr library, string function, bool throwIfNotFound = false)
        {
            IntPtr result;

            if (Environment.OSVersion.IsWindows())
            {
                result = Windows.GetProcAddress(library, function);
            }
            else if (Environment.OSVersion.IsMacOSX())
            {
                result = OSX.dlsym(library, function);
            }
            else
            {
                result = Linux.dlsym(library, function);
            }

            if (result == IntPtr.Zero)
            {
                if (throwIfNotFound)
                {
                    throw new EntryPointNotFoundException(function);
                }

                return(default(T));
            }

            return(Marshal.GetDelegateForFunctionPointer <T>(result));
        }
Example #4
0
        public static bool TryLoadFunction <T>(
            IntPtr library,
            string functionName,
            [NotNullWhen(true)] out T?func)
            where T : Delegate
        {
            IntPtr ret;

            if (PlatformInfo.CurrentOS == PlatformInfo.OS.Windows)
            {
                ret = Windows.GetProcAddress(library, functionName);
            }
            else if (PlatformInfo.CurrentOS == PlatformInfo.OS.MacOSX)
            {
                ret = OSX.dlsym(library, functionName);
            }
            else
            {
                ret = Linux.dlsym(library, functionName);
            }

            if (ret == IntPtr.Zero)
            {
                func = default;
                return(false);
            }

            func = Marshal.GetDelegateForFunctionPointer <T>(ret);
            return(true);
        }
            public static IntPtr GetProcAddress(IntPtr library, string function)
            {
                var num = !IsWindows
                    ? !IsOSX?Linux.dlsym(library, function) : OSX.dlsym(library, function)
                              : Windows.GetProcAddress(library, function);

                return(num);
            }
Example #6
0
            public static IntPtr GetProcAddress(IntPtr library, string function)
            {
                var num = !IsWindows ? (!IsOSX ? Linux.dlsym(library, function) : OSX.dlsym(library, function)) : Windows.GetProcAddress(library, function);

                if (num == IntPtr.Zero)
                {
                    Logger.Warn("Função não encontrada: " + function);
                }
                return(num);
            }
Example #7
0
        public static IntPtr GetProcAddress(IntPtr library, string function)
        {
            var ret = IntPtr.Zero;

            if (IsWindows)
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (IsOSX)
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            return(ret);
        }
Example #8
0
        public static T LoadFunction <T>(IntPtr library, string function)
        {
            IntPtr ret;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            if (ret == IntPtr.Zero)
            {
                throw new EntryPointNotFoundException(function);
            }

            return(Marshal.GetDelegateForFunctionPointer <T>(ret));
        }
Example #9
0
    public static IntPtr GetProcAddress(IntPtr library, string function)
    {
        var ret = IntPtr.Zero;

        if (IsWindows)
        {
            ret = Windows.GetProcAddress(library, function);
        }
        else if (IsOSX)
        {
            ret = OSX.dlsym(library, function);
        }
        else
        {
            ret = Linux.dlsym(library, function);
        }

        if (ret == IntPtr.Zero)
        {
            Console.WriteLine("[WARNING] Function not found: " + function);
        }

        return(ret);
    }
Example #10
0
        public static T LoadFunction <T>(IntPtr library, string function)
        {
            var ret = IntPtr.Zero;

            if (IsWindows)
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (IsOSX)
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            if (ret == IntPtr.Zero)
            {
                return(default(T));
            }

            return(Marshal.GetDelegateForFunctionPointer <T>(ret));
        }