Skip to content

Gtk Sharp within Windows #442

Closed
Closed
@Hecatron

Description

@Hecatron

Hi, I've recently been trying out Eto.Forms using different backends under Windows 10 (since I'm looking for a cross platform toolkit).

One things I have noticed when running the Eto.Test.Gtk2
under windows 10 / Visual Studio 2015 / with the latest Gtk Sharp
was the following exception
"Unable to load DLL 'libgtk-win32-2.0-0.dll': The specified procedure could not be found"

This led me to this link https://forums.xamarin.com/discussion/15568/unable-to-load-dll-libgtk-win32-2-0-0-dll

It turns out the fix is to include a function which fixes up most of the issues with the finding of gtk dll's when running under windows
The following seems to fix the problem, although I'm not sure if this is something that needs to be rolled into Eto.Forms or not in some way

namespace Eto.Test.Gtk2
{
    class Startup
    {
        //[STAThread]
        static void Main(string[] args)
        {
            CheckWindowsGtk(); // Fixes GTK library find issues
            var platform = new Eto.GtkSharp.Platform();

            var app = new TestApplication(platform);
            app.TestAssemblies.Add(typeof(Startup).Assembly);
            app.Run();
        }

        static bool CheckWindowsGtk()
        {
            string location = null;
            Version version = null;
            Version minVersion = new Version(2, 12, 22);
            using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Xamarin\GtkSharp\InstallFolder"))
            {
                if (key != null)
                    location = key.GetValue(null) as string;
            }
            using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Xamarin\GtkSharp\Version"))
            {
                if (key != null)
                    Version.TryParse(key.GetValue(null) as string, out version);
            }
            //TODO: check build version of GTK# dlls in GAC
            if (version == null || version < minVersion || location == null || !File.Exists(Path.Combine(location, "bin", "libgtk-win32-2.0-0.dll")))
            {
                Console.WriteLine("Did not find required GTK# installation");
                //  string url = "http://monodevelop.com/Download";
                //  string caption = "Fatal Error";
                //  string message =
                //      "{0} did not find the required version of GTK#. Please click OK to open the download page, where " +
                //      "you can download and install the latest version.";
                //  if (DisplayWindowsOkCancelMessage (
                //      string.Format (message, BrandingService.ApplicationName, url), caption)
                //  ) {
                //      Process.Start (url);
                //  }
                return false;
            }
            Console.WriteLine("Found GTK# version " + version);
            var path = Path.Combine(location, @"bin");
            Console.WriteLine("SetDllDirectory(\"{0}\") ", path);
            try
            {
                if (SetDllDirectory(path))
                {
                    return true;
                }
            }
            catch (EntryPointNotFoundException)
            {
            }
            // this shouldn't happen unless something is weird in Windows
            Console.WriteLine("Unable to set GTK+ dll directory");
            return true;
        }

        [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true)]
        [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
        static extern bool SetDllDirectory(string lpPathName);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions