Exemple #1
0
        static T LoadEntrypoint <T>(IntPtr dll, string name) where T : class
        {
            if (!PlatformDetection.IsWindows || IntPtr.Size != 4)
            {
                name = name.Substring(1, name.IndexOf('@') - 1);
            }

            var address = PlatformDetection.IsWindows ? Win32.GetProcAddress(dll, name)
                        : PlatformDetection.IsMac ? Mac.dlsym(dll, name)
                        : IntPtr.Zero;
            var result = address != IntPtr.Zero
                       ? Marshal.GetDelegateForFunctionPointer(address, typeof(T)) as T
                       : null;

            if (result != null)
            {
                return(result);
            }

            throw new NativeException("Failed to get address of '" + name + "'");
        }