[Mono-list] Using P/Invoke

Aaron Bockover aaron.lists@aaronbock.net
Fri, 08 Apr 2005 09:40:31 -0400


Hello, one area I haven't had much practice in with Mono is P/Invoke. I
am trying to import a function from libgimp, so I can use a custom GTK
widget in the library.

Here is what I've tried:

using System;
using System.Runtime.InteropServices;
using Gtk;
using GLib;

public class GimpColorButton : Button
{
        [DllImport("/usr/lib/libgimpwidgets-2.0")]
        static extern IntPtr gimp_color_button_new();

        public GimpColorButton() : base(IntPtr.Zero)
        {
                base.Raw = gimp_color_button_new();
        }

        ~GimpColorButton()
        {
                Dispose();
        }
}

...

Widget colorButton = new GimpColorButton();

As for the actual Gimp Library, I think maybe multiple libraries have to
be loaded (libgimpcolor, libgimpui, etc.) So maybe I should write a
wrapper C library that links in all the Gimp libraries, and then import
that library into the C#? Regardless of the C library in question, is
the C# above on the right track?

Thanks!

--Aaron Bockover