Пример #1
0
    private static bool LoadDynamicLibrary(SupportedPlatform platform, string name, out IntPtr handle, out string location)
    {
        switch (platform)
        {
        case SupportedPlatform.Windows:
            handle = NativeWindowsMethods.LoadLibrary(name);
            if (handle == IntPtr.Zero)
            {
                goto default;
            }
            location = GetLocationWindows(handle) ?? name;
            return(true);

        case SupportedPlatform.Linux:
        case SupportedPlatform.MacOSX:
            handle = NativeUnixMehods.dlopen(name, 2 /* RTLD_NOW */);
            if (handle == IntPtr.Zero)
            {
                goto default;
            }
            location = GetLocationUnix(handle) ?? name;
            return(true);

        default:
            handle   = IntPtr.Zero;
            location = null;
            return(false);
        }
    }
Пример #2
0
    public static void LoadDynamicLibrary(SupportedPlatform platform, string[] possibleNames, out IntPtr handle, out string location)
    {
        if (platform != SupportedPlatform.Android)
        {
            throw new NotSupportedException();
        }
        foreach (string possibleName in possibleNames)
        {
            handle = NativeUnixMehods.dlopen(possibleName, 2 /* RTLD_NOW */);
            if (handle != IntPtr.Zero)
            {
                location = possibleName;
                return;
            }
        }
        string message = string.Join(", ", possibleNames);

        throw new DllNotFoundException(message, GetLastError());
    }