[Mono-list] PInvoke to libgda

Daniel Morgan danmorg@sc.rr.com
Thu, 7 Feb 2002 18:57:03 -0500


Adam,

I hope you don't mind, I couldn't help resist reposting this to the
mono-list. ;-)

-= Daniel

----- Original Message -----
From: "Adam Treat" <manyoso@yahoo.com>
To: "Daniel Morgan" <danmorg@sc.rr.com>
Sent: Thursday, February 07, 2002 6:42 PM
Subject: Re: [Mono-list] PInvoke Test


> > Do you have an example you care to share with us of how you connected to
a
> > database using libgda through C#?  I am definitely most interested in
> > working on this.
>
> Yah, I haven't actually been doing anything with libgda, I am working on
> binding the Qt toolkit to c#...  But, I took a stab at some PInvoke calls
to
> libgda-common just to get you started.  See below.  Hope it helps.
>
> > I would like to use csc.exe on Linux, but Red Hat Linux does not support
> > NTFS out of the box.  That would be really cool if I could though -- not
> > having to switch back and forth between Windows and Linux -- just stay
in
> > Linux and make C# programs.
>
> I have a windows partition that I installed specifically to work on Mono.
> But, I grew tired of working in windows so I set up wine to use csc.  It
is
> so much nicer than monkeying with the windows command line ;-)
>
> cheers,
>
> adam
>
> // libgda PInvoke example with Mono's mint on linux.
>
> using System;
> using System.Runtime.InteropServices;
> public class libgda
> {
>
> [DllImport("libgda-common.so.0", EntryPoint="gda_init")]
> public static extern void gda_init(
> [MarshalAs(UnmanagedType.LPStr)] string app_id,
> [MarshalAs(UnmanagedType.LPStr)] string version,
> ref int nargs,
> [MarshalAs(UnmanagedType.LPStr)] string args);
> //ref IntPtr args);
>
> public static int Main(string[] argv)
> {
>
> // Notice, I am faking it when it comes to the command line args.  This
> // is where the Marshal class would come in handy (See below)
> int argc = 1;
> gda_init("app", "version", ref argc, "my_argument");
> return 0;
>
> // This is what you really want, unfortunately the mint
> // interpreter does not have support for the full Marshal class
> // so you'll have to wait for that in order to pass char *args[] to it.
> // But, this should at least get you up and running.
> //int argc = argv.Length;
> //IntPtr args = Marshal.StringToHGlobalAnsi(argv);
> //gda_init("app, "version", ref argc, ref args);
> }
> }