public ResolvePathResult Resolve(string library)
        {
            var result = _original.Resolve(library);

            if (!result.IsSuccess && library == "QmlNet")
            {
                // Try to let .NET load the library.
                try
                {
                    qml_net_getVersion();

                    // The method invoked correctly, so .NET loaded it.
                    // Let's return the path to it.
                    var loaded = GetModuleHandle("QmlNet");

                    var bytes = Marshal.AllocHGlobal(2000);
                    var r     = GetModuleFileName(loaded, bytes, 2000);
                    var path  = Marshal.PtrToStringAnsi(bytes);
                    Marshal.FreeHGlobal(bytes);

                    if (File.Exists(path))
                    {
                        return(ResolvePathResult.FromSuccess(path));
                    }
                }
                catch (Exception)
                {
                }
            }

            return(result);
        }
Example #2
0
        public ResolvePathResult Resolve(string library)
        {
            var result = _original.Resolve(library);

            if (!result.IsSuccess && library == "QmlNet")
            {
                // Try to let .NET load the library.
                try
                {
                    qml_net_getVersion();

                    using (var currentProcess = Process.GetCurrentProcess())
                    {
                        foreach (ProcessModule module in currentProcess.Modules)
                        {
                            if (Path.GetFileNameWithoutExtension(module.FileName) == "libQmlNet")
                            {
                                return(ResolvePathResult.FromSuccess(module.FileName));
                            }
                        }
                    }
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch (Exception)
                // ReSharper restore EmptyGeneralCatchClause
                {
                }
            }

            return(result);
        }
Example #3
0
 public ResolvePathResult Resolve(string library)
 {
     try
     {
         var path = LibPathResolver.Resolve(library);
         return(ResolvePathResult.FromSuccess(path));
     }
     catch (Exception ex)
     {
         return(ResolvePathResult.FromError(ex));
     }
 }
        public ResolvePathResult Resolve(string library)
        {
            var result = _original.Resolve(library);

            if (!result.IsSuccess && library == "QmlNet")
            {
                // Try to let .NET load the library.
                try
                {
                    qml_net_getVersion();

                    // The method invoked correctly, so .NET loaded it.
                    // Let's return the path to it.
                    var dll = dlopen("libQmlNet.dylib", SymbolFlag.RtldLazy);
                    if (dll == IntPtr.Zero)
                    {
                        return(result);
                    }

                    var sym = dlsym(dll, "qml_net_getVersion");
                    if (sym == IntPtr.Zero)
                    {
                        return(result);
                    }


                    var info = new DlInfo();
                    if (dladdr(sym, ref info) != 1)
                    {
                        return(result);
                    }

                    var location = Marshal.PtrToStringAnsi(info.fname);

                    if (File.Exists(location))
                    {
                        return(ResolvePathResult.FromSuccess(location));
                    }
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch (Exception)
                // ReSharper restore EmptyGeneralCatchClause
                {
                }
            }

            return(result);
        }
Example #5
0
 public ResolvePathResult Resolve(string library)
 {
     return(ResolvePathResult.FromSuccess(library));
 }