[Mono-list] Using P/Invoke
Aaron Bockover
aaron.lists@aaronbock.net
Fri, 08 Apr 2005 11:11:02 -0400
It might have something to do with Ubuntu. I just moved from Slackware,
where I installed everything from source, to Ubuntu. Gimp came installed
by default, but none of the headers were installed. So I installed
gimp-dev yesterday, and ran ldconfig of course. Under Slackware,
DllImport worked fine with libraries in a standard location. Either way
it's a non issue to me because the build system will generate a runtime
config. But yes, it's still quite odd.
My Mono 1.1.6 stack is one of the few applications/platforms on Ubuntu
that I have built entirely from source, simply because what's in the
repositories is old, and I'd just prefer to have this platform from
source. Maybe
--Aaron
On Fri, 2005-04-08 at 10:57 -0400, Nigel Benns wrote:
> Thats really weird that it didn't find it.
> Did you just install the gimp? I would run ldconfig and then check and
> see what its listed as in the cache.
>
> > Regarding the DllImport, just using "libgimpwidget-2.0" did not work,
> > but it's not an issue. I hardcoded the path to just make sure it would
> > import properly. When I merge this into the rest of the project, I'll be
> > checking for the Gimp libraries in configure, and generate a runtime
> > config file for the assembly that has the library paths for the Gimp
> > library in it.
> >
> > As for the base.Raw, I'm about to try your alternative.
> >
> > Thanks for the insight!
> > --Aaron
> >
> >
> > On Fri, 2005-04-08 at 10:27 -0400, Nigel Benns wrote:
> >> It looks pretty good to me :)
> >>
> >> I wouldn't use "/usr/lib/libgimpwidgets-2.0" in the DLLImport field
> >> though.
> >> Use either "libgimpwidgets-2.0" or "gimpwidgets" may work as well. It
> >> will make it more portable, so that it works on windows.
> >>
> >> I don't think I would use base.Raw either, but you might want to ask
> >> someone else on this. When doing EFL-Sharp, I've been overriding Raw
> >> for
> >> the class, and having it setup an IntPtr within the class. That way I
> >> can
> >> control that its only a "get" operation (I can't see a reason to set
> >> it),
> >> and I can use a HandleRef instead to make sure nothing inadvertantly
> >> gets
> >> GC'ed before the class is finalized.
> >>
> >> public class GimpColorButton : Button
> >> {
> >> [DllImport("libgimpwidgets-2.0")]
> >> static extern IntPtr gimp_color_button_new();
> >>
> >> HandleRef realWidget;
> >>
> >> public GimpColorButton() : base(IntPtr.Zero)
> >> {
> >> realWidget = new HandleRef(this,
> >> gimp_color_button_new());
> >> }
> >>
> >> public override IntPtr Raw
> >> {
> >>
> >> get {
> >>
> >> return this.realWidget.Handle;
> >>
> >> }
> >>
> >> }
> >>
> >> ~GimpColorButton()
> >> {
> >> Dispose();
> >> }
> >> }
> >>
> >>
> >> > 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
> >> >
> >> >
> >> > _______________________________________________
> >> > Mono-list maillist - Mono-list@lists.ximian.com
> >> > http://lists.ximian.com/mailman/listinfo/mono-list
> >> >
> >>
> >> _______________________________________________
> >> Mono-list maillist - Mono-list@lists.ximian.com
> >> http://lists.ximian.com/mailman/listinfo/mono-list
> >>
> >>
> >
> > _______________________________________________
> > Mono-list maillist - Mono-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
> >
>
>
>