[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] some example C# code that call GLPK in C# from visual st
From: |
Heinrich Schuchardt |
Subject: |
Re: [Help-glpk] some example C# code that call GLPK in C# from visual studio 2013 |
Date: |
Mon, 13 Apr 2015 13:30:11 +0200 |
Hello Nigel,
GLPK does not call SetLastError. So why do you want it in the declaration?
I guess you want to remove unsafe because no pointer to a C# object is passed
to GLPK?
Best regards
Heinrich Schuchardt
Am 13.04.15 um 13:15 schrieb Nigel Galloway
> Looking at the example in the wiki, in C# 5 the following works fine:
>
>
>
> using System;
>
> using System.Runtime.InteropServices;
>
>
>
>
>
> class test {
>
> [DllImport("glpk.dll", SetLastError = true)]
>
> static extern IntPtr glp_version();
>
>
>
> public static void Main(string[] args) {
>
> Console.WriteLine("Version is {0}",
>
> Marshal.PtrToStringAnsi(glp_version()));
>
> }
>
> }
>
>
>
> producing:
>
>
>
> Version is 4.55.
>
>
>
> This is safe and does not require to be compiled with the unsafe flag.
>
> In t1.cs the part that makes it unsafe is the use of fixed to define ia
>
> ar and ja. In C# 5 these can be marshalled with UnmanagedType.LPArray.
>
> Most of the straight forward interface to glpk can be linked safely. The
>
> main problem arises when you have to obtain a structure defined in C
>
> from glpk which you have to modify in C# and return to glpk.
>
>
>
> --
>
> Nigel Galloway
>
> address@hidden
>
>
>
> On Tue, Apr 7, 2015, at 05:10 AM, Heinrich Schuchardt wrote:
>
> > Hello Nigel,
>
> >
>
> > how would you call native dlls in C# 5?
>
> > Is this supported in Mono, too?
>
> >
>
> > Best regards
>
> >
>
> > Heinrich Schuchardt
>
> >
>
> >
>
> > Am 07.04.15 um 13:30 schrieb Nigel Galloway
>
> >
>
> > > There is also an example in glpk's example directory. But this and the
>
> > >
>
> > > wiki are very old examples (C# 2.0 I think). This is not how to do it
>
> > >
>
> > > with C# 4 or 5.
>
> > >
>
> > >
>
> > >
>
> > > --
>
> > >
>
> > > Nigel Galloway
>
> > >
>
> > > address@hidden
>
> > >
>
> > >
>
> > >
>
> > > On Wed, Apr 1, 2015, at 10:50 AM, Heinrich Schuchardt wrote:
>
> > >
>
> > > > Please, see http://en.wikibooks.org/wiki/GLPK/C-Sharp
>
> > >
>
> > > > and read
>
> > >
>
> > > > https://msdn.microsoft.com/en-us/library/26thfadc%28v=vs.110%29.aspx
>
> > >
>
> > > > (Consuming Unmanaged DLL Functions)
>
> > >
>
> > > >
>
> > >
>
> > > > Best regards
>
> > >
>
> > > >
>
> > >
>
> > > > Heinrich Schuchardt
>
> > >
>
> > > >
>
> > >
>
> > > > On 01.04.2015 17:50, usa usa wrote:
>
> > >
>
> > > > > Hi,
>
> > >
>
> > > > >
>
> > >
>
> > > > > Could anybody recommand some example C# code that call GLPK in C# from
>
> > >
>
> > > > > visual studio 2013 on win 7 ?
>
> > >
>
> > > > >
>
> > >
>
> > > > > I am new to use GLPK from C#.
>
> > >
>
> > > > >
>
> > >
>
> > > > > Any help would be appreciated.
>
> > >
>
> > > > >
>
> > >
>
> > > > > thanks
>
> > >
>
> > > >
>
> > >
>
> > > >
>
> > >
>
> > > > _______________________________________________
>
> > >
>
> > > > Help-glpk mailing list
>
> > >
>
> > > > address@hidden
>
> > >
>
> > > > https://lists.gnu.org/mailman/listinfo/help-glpk
>
> > >
>
> > >
>
> > >
>
> > > --
>
> > >
>
> > > http://www.fastmail.com - IMAP accessible web-mail
>
> > >
>
> > >
>
> > >
>
> > >
>
> > >
>
> > > _______________________________________________
>
> > >
>
> > > Help-glpk mailing list
>
> > >
>
> > > address@hidden
>
> > >
>
> > > https://lists.gnu.org/mailman/listinfo/help-glpk
>
>
>
> --
>
> http://www.fastmail.com - Access all of your messages and folders
>
> wherever you are