|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
|
|
|
RE: Fwd: lpsolve55.csCan you give an example which shows how to use get_col_name correctly in the
C# caller? Where does the new helper function intPtrToString(.) come into play? [DllImport("lpsolve55.dll", SetLastError=true)] public static extern IntPtr get_col_name(IntPtr lp, int column); public static string intPtrToString(IntPtr str) { return Marshal.PtrToStringAnsi(str); } Was previously in 5.5.0.15 [DllImport("lpsolve55.dll", EntryPoint = "get_col_name", SetLastError = true)] private unsafe static extern IntPtr get_col_name_c(int lp, int column); public static string get_col_name(int lp, int column) { return (Marshal.PtrToStringAnsi(get_col_name_c(lp, column))); } The issue is to dispose of the unsafe modifier. Does your code work? William _____ From: lp_solve@... [mailto:lp_solve@...] On Behalf Of Michael Bowerman Sent: Thursday, October 22, 2009 10:47 AM To: lp_solve@... Subject: [lp_solve] Fwd: lpsolve55.cs [1 Attachment] [Attachment(s) from Michael Bowerman included below] ---------- Forwarded message ---------- From: Michael Bowerman <michael.bowerman@ <mailto:michael.bowerman@...> gmail.com> Date: Thu, Oct 22, 2009 at 10:43 AM Subject: lpsolve55.cs To: lp_solve@yahoogroup <mailto:lp_solve@...> s.com I have updated the lpsolve55.cs wrapper to handle arrays and return strings properly. |
|
|
Re: Fwd: lpsolve55.cs [1 Attachment]It looks like I was working off version 5.5.0.9, woops! The definition in
version 5.5.0.15 is better for string returns, since my version needs 2 function calls where 5.5.0.15 needs only 1. I think the unsafe keyword is unecessary due to the fact that the only pointers operated on are in C unmanaged memory. It looks like the strings and arrays are correct in 5.5.0.15 as well. The only real change that I see now is changing all the ``int lp'' to ``IntPtr lp'' and all the functions that return ``int'' for an lprec should be ``IntPtr'' as well (e.g. make_lp, copy_lp, etc.). IntPtr is holds the size of a native pointer. So, 64-bit might be truncated. I have attached an updated copy based on the latest version. Thanks. _bowerman On Thu, Oct 22, 2009 at 5:11 PM, William H. Patton <pattonwh@...>wrote: > > > Can you give an example which shows how to use get_col_name correctly in > the C# caller? > > Where does the new helper function intPtrToString(…) come into play? > > > > [DllImport("lpsolve55.dll", SetLastError=true)] public static > extern IntPtr get_col_name(IntPtr lp, int column); > > > > public static string intPtrToString(IntPtr str) > > { > > return Marshal.PtrToStringAnsi(str); > > } > > > > Was previously in 5.5.0.15 > > [DllImport("lpsolve55.dll", EntryPoint = "get_col_name", > SetLastError = true)] private unsafe static extern IntPtr > get_col_name_c(int lp, int column); > > public static string get_col_name(int lp, int column) > > { > > return (Marshal.PtrToStringAnsi(get_col_name_c(lp, column))); > > } > > > > The issue is to dispose of the unsafe modifier. Does your code work? > > > > William > > > ------------------------------ > > *From:* lp_solve@... [mailto:lp_solve@...] *On > Behalf Of *Michael Bowerman > *Sent:* Thursday, October 22, 2009 10:47 AM > > *To:* lp_solve@... > *Subject:* [lp_solve] Fwd: lpsolve55.cs [1 Attachment] > > > > > > > > ---------- Forwarded message ---------- > From: *Michael Bowerman* <michael.bowerman@...> > Date: Thu, Oct 22, 2009 at 10:43 AM > Subject: lpsolve55.cs > To: lp_solve@... > > > I have updated the lpsolve55.cs wrapper to handle arrays and return strings > properly. > > > > > |
| Free embeddable forum powered by Nabble | Forum Help |