예제 #1
0
    public static void GetLibraryMethod <T>(SupportedPlatform platform, IntPtr handle, string name, out T t)
    {
        IntPtr result;

        switch (platform)
        {
        case SupportedPlatform.Windows:
            result = NativeWindowsMethods.GetProcAddress(handle, name);
            if (result == IntPtr.Zero)
            {
                throw new EntryPointNotFoundException(name, GetLastWindowsError());
            }
            break;

        case SupportedPlatform.Linux:
        case SupportedPlatform.MacOSX:
            result = NativeUnixMehods.dlsym(handle, name);
            if (result == IntPtr.Zero)
            {
                throw new EntryPointNotFoundException(name, GetLastErrorUnix());
            }
            break;

        default: throw new NotSupportedException();
        }
        t = (T)(object)Marshal.GetDelegateForFunctionPointer(result, typeof(T));
    }
예제 #2
0
    private static string GetLocationUnix(IntPtr handle)
    {
        IntPtr symbol = NativeUnixMehods.dlsym(handle, "ts3client_freeMemory");

        NativeUnixMehods.Dl_info dl_info = new NativeUnixMehods.Dl_info();
        if (symbol == IntPtr.Zero || NativeUnixMehods.dladdr(symbol, ref dl_info) == 0)
        {
            return(null);
        }
        return(dl_info.dli_fname);
    }
예제 #3
0
    public static void GetLibraryMethod <T>(SupportedPlatform platform, IntPtr handle, string name, out T t)
    {
        if (platform != SupportedPlatform.Android)
        {
            throw new NotSupportedException();
        }
        IntPtr result = NativeUnixMehods.dlsym(handle, name);

        if (result == IntPtr.Zero)
        {
            throw new EntryPointNotFoundException(name, GetLastError());
        }
        t = (T)(object)Marshal.GetDelegateForFunctionPointer(result, typeof(T));
    }