summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eo_mono/NativeModule_Unix.cs
blob: 9aba31b0167b86ec1df0050b92f2fea975278c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Runtime.InteropServices;

namespace Efl { namespace Eo {

public partial class NativeModule
{
    public const int RTLD_NOW = 0x002;

    [DllImport(efl.Libs.Libdl)]
    public static extern IntPtr dlopen(string fileName, int flag);
    [DllImport(efl.Libs.Libdl)]
    public static extern int dlclose(IntPtr handle);

    public static void UnloadLibrary(IntPtr handle)
    {
        dlclose(handle);
    }
    
    public static IntPtr LoadLibrary(string filename)
    {
        Console.WriteLine("Loading library {0}", filename);
        var r = dlopen(filename, RTLD_NOW);
        if (r == IntPtr.Zero)
        {
            r = dlopen("lib" + filename, RTLD_NOW);
            if (r == IntPtr.Zero)
            {
                r = dlopen(filename + ".so", RTLD_NOW);
                if (r == IntPtr.Zero)
                {
                    r = dlopen("lib" + filename + ".so", RTLD_NOW);
                }
            }
        }
        return r;
    }
}




} }