[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RE: [Help-glpk] VBA/dll for Excel
From: |
glpk xypron |
Subject: |
Re: RE: [Help-glpk] VBA/dll for Excel |
Date: |
Wed, 19 Mar 2008 04:03:06 +0100 |
Hello Marc,
The following module correctly shows a collected message until GLPK aborts the
program due to the nonexistent column, using the library in
ftp://glpk.dyndns.org/glpk/glpk_4_27.dll.stdcall.zip
(see my prior mail).
Attribute VB_Name = "TestGLPK"
Option Explicit
Public Declare Function glp_create_prob Lib "c:\temp\glpk\glpk_4_27.dll" () As
Long
Public Declare Sub glp_set_prob_name Lib "c:\temp\glpk\glpk_4_27.dll" (ByVal lp
As Long, ByVal name As String)
Public Declare Sub glp_delete_prob Lib "c:\temp\glpk\glpk_4_27.dll" (ByVal lp
As Long)
Public Declare Function glp_get_prob_name Lib "c:\temp\glpk\glpk_4_27.dll"
(ByVal lp As Long) As Long
Public Declare Sub glp_term_hook Lib "c:\temp\glpk\glpk_4_27.dll" (ByVal func
As Long, info As Long)
Public Declare Sub glp_set_col_name Lib "c:\temp\glpk\glpk_4_27.dll" (ByVal lp
As Long, ByVal j As Long, ByVal name As String)
Private Declare Function SysAllocStringByteLen Lib "oleaut32" (ByVal pwsz As
Long, ByVal length As Long) As String
Public Function MessageHandler(ByVal info As Long, ByVal msg As Long) As Long
Static collect
Dim mess As String
mess = SysAllocStringByteLen(msg, 1024)
mess = Left$(mess, InStr(mess, Chr$(0)) - 1)
collect = collect & mess
MsgBox collect
MessageHandler = 0
End Function
Sub test()
Dim i As Long
Dim l As Long
Dim lp As Long
Dim info As Long
Dim name As String
lp = glp_create_prob()
Call glp_term_hook(AddressOf MessageHandler, info)
name = "MyProblem"
Call glp_set_prob_name(lp, name)
name = "nonsense"
Call glp_set_col_name(lp, 100, name)
name = ""
l = glp_get_prob_name(lp)
name = SysAllocStringByteLen(l, 512)
Call glp_delete_prob(lp)
End Sub
-------- Original-Nachricht --------
> Datum: Tue, 18 Mar 2008 12:49:35 -0400
> Von: "Meketon, Marc" <address@hidden>
> An: address@hidden
> CC: "Xypron" <address@hidden>
> Betreff: RE: [Help-glpk] VBA/dll for Excel
> Thanks.
>
> I produced a DLL as well by adding __stdcall __export to the right
> function calls. [BTW, I'm using the free Turbo C++ compiler from
> Borland.]
>
> BUT, I cannot seem to get the callback function for "glp_term_hook" to
> properly work. Before I begin to setup the problem, I use very similar
> VBA code to what the Version 10 of the Informatiks software uses:
>
> Const MAXMSG as long = 500
> Private ActMsg as long
>
> Private Messages(MAXMSG) as string
>
> Public sub INIT_GLPK()
> Dim info as long
>
> info = 0
> glp_term_hook AddressOf MessageHandler, info
> ActMsg = 0
> end sub
>
> and
>
> public function MessageHandler(ByVal info As Long, ByVal msg As Long)
> As Long
> Dim l As Long
> Dim Err_Message As String
>
> On Error Resume Next
>
> If ActMsg < MAXMSG Then
> ActMsg = ActMsg + 1
> End If
> l = lstrlen(msg)
> Err_Message = Space$(l + 1)
> lstrcpy Err_Message, msg
> Err_Message = Left(Err_Message, l)
> Messages(ActMsg) = Err_Message
>
> MessageHandler = 1
> End Function
>
> However, when the "xputs" function in GLPK tries to return, the code
> bombs. The "xputs" does call the "MessageHandler", and it seems to pass
> in the correct string, and xputs does see the correct return. I believe
> that somehow the stack gets messed up a bit, but I haven't figured out
> any workaround.
>
> Any ideas on how to successfully invoke the call-back function for the
> terminal hook?
>
> -Marc
> -----Original Message-----
> From: Xypron [mailto:address@hidden
> Sent: Tuesday, March 18, 2008 10:53 AM
> To: Meketon, Marc
> Cc: address@hidden
> Subject: Re: [Help-glpk] VBA/dll for Excel
>
> Hello Marc,
>
> couldn't You use the DLL produced by
> w32/Build_GLPK_with_VC6_MT_DLL.bat
> with Visual C++ 7.0 or 6.0?
> (see ftp://glpk.dyndns.org/glpk/glpk_4_27.dll.tar.gz)
>
> Best regards
>
> Xypron
>
> Meketon, Marc wrote:
> >
> > A while back there was a version of GLPK for VBA applications (such as
>
> > in Excel). That was based on version 10 of GLPK. Does anyone work with
>
> > GLPK in VBA with a recent version of the software? If so, can you
> > please provide links? It appears that the original folks (Informatik
> > Fuchs) do have a version 23, but it's on a CD for 50 euros, and there
> > is no English page for it, so I'm not sure how possible it will be for
>
> > me to get the CD.
> >
> > FYI, the German web page for the version 10 VBA implementation is:
> > http://www.informatikfuchs.de/Software/GLPK/glpkVBDownload.htm (and
> > there is a link for the English version of this web page on this
> page).
> >
> > -Marc Meketon
> >
> >
> ------------------------------------------------------------------------
> ----
> >
> > This e-mail and any attachments may be confidential or legally
> > privileged. If you received this message in error or are not the
> > intended recipient, you should destroy the e-mail message and any
> > attachments or copies, and you are prohibited from retaining,
> > distributing, disclosing or using any information contained herein.
> > Please inform us of the erroneous delivery by return e-mail.
> >
> > Thank you for your cooperation.
> >
> ------------------------------------------------------------------------
> ----
> >
> >
> ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Help-glpk mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/help-glpk
> >
>
> ----------------------------------------------------------------------------
> This e-mail and any attachments may be confidential or legally privileged.
> If you received this message in error or are not the intended recipient,
> you should destroy the e-mail message and any attachments or copies, and
> you are prohibited from retaining, distributing, disclosing or using any
> information contained herein. Please inform us of the erroneous delivery by
> return e-mail.
>
> Thank you for your cooperation.
> ----------------------------------------------------------------------------
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
- [Help-glpk] VBA/dll for Excel, Meketon, Marc, 2008/03/17
- Re: [Help-glpk] VBA/dll for Excel, Xypron, 2008/03/18
- RE: [Help-glpk] VBA/dll for Excel, Meketon, Marc, 2008/03/18
- Re: [Help-glpk] VBA/dll for Excel, Andrew Makhorin, 2008/03/18
- Re: RE: [Help-glpk] VBA/dll for Excel,
glpk xypron <=
- [Help-glpk] Hook needed in xfault(), glpk xypron, 2008/03/18
- Re: [Help-glpk] Hook needed in xfault(), Andrew Makhorin, 2008/03/19
- Re: [Help-glpk] Hook needed in xfault(), glpk xypron, 2008/03/19
- Re: [Help-glpk] Hook needed in xfault(), Andrew Makhorin, 2008/03/19
- Re: [Help-glpk] Hook needed in xfault(), glpk xypron, 2008/03/19
- Re: [Help-glpk] Hook needed in xfault(), Andrew Makhorin, 2008/03/19
RE: [Help-glpk] VBA/dll for Excel, Meketon, Marc, 2008/03/18