[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: RE: [Help-glpk] VBA/dll for Excel

From: Meketon, Marc
Subject: RE: RE: [Help-glpk] VBA/dll for Excel
Date: Tue, 18 Mar 2008 22:44:43 -0400

Wow, you did a lot of work.  Thank you very much!

I'll be trying it out tomorrow night, and I'll let you know if it solves
the stack pointer address problem that I have.


-----Original Message-----
From: glpk xypron [mailto:address@hidden 
Sent: Tuesday, March 18, 2008 10:04 PM
To: Meketon, Marc
Cc: address@hidden; address@hidden
Subject: Re: RE: [Help-glpk] VBA/dll for Excel

Hello Marc,

the problem is due to GLPK being compiled with __cdecl calling
convention instead of __stdcall calling convention.


I have recompiled the DLL with compiler switch /Gz
CFLAGS = /nologo /W3 /DGLP_TLS_CONFIG=2 /Gz

This gave me a lot of errors of type:
..\src\glplpx05.c(725) : error C2440: 'Function': 'int (__stdcall
*)(const void *,const void *)' cannot be converted to 'int (__cdecl
t void *,const void *)'

All functions passed to qsort must be explicitly declared as __cdecl,

/* Define __cdecl for non-Microsoft compilers */
#if     ( !defined(_MSC_VER) && !defined(__cdecl) )
#define __cdecl
static int __cdecl fcmp(const void *ptr1, const void *ptr2)

Concerned files are:

The created library can be download at

The source changes can be viewed at
svn co svn://

With this library the following subroutine in VBA ran without errors:

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
Private Declare Function SysAllocStringByteLen Lib "oleaut32" (ByVal
pwsz As Long, ByVal length As Long) As String

Sub test()
  Dim i    As Long
  Dim l    As Long
  Dim lp   As Long
  Dim name As String
  lp = glp_create_prob()
  name = "MyProblem"
  Call glp_set_prob_name(lp, name)
  name = ""
  l = glp_get_prob_name(lp)
  name = SysAllocStringByteLen(l, 512)
  name = Left$(name, InStr(name, Chr$(0)) - 1)
  MsgBox name, vbOKOnly, "Name of the Problem"
  Call glp_delete_prob(lp)
End Sub

Please, inform me if this solves You problem.

Best regards


-------- Original-Nachricht --------
> Datum: Tue, 18 Mar 2008 14:46:42 -0400
> Von: "Meketon, Marc" <address@hidden>
> An: "Xypron" <address@hidden>
> CC: address@hidden
> Betreff: RE: [Help-glpk] VBA/dll for Excel

> I just tried glpk_4_27.dll from your distribution, and am having a
> difficulty.
> In the following VBA code, 
>     Dim lp       As Long
>     lp = glp_create_prob()
>     glp_set_prob_name lp, "sample"
> The line "lp = glp_create_prob()" works, but the next line
> (glp_set_prob_name lp, "sample") gets an error message of "Bad DLL
> calling convention".  Are these function calls based on the "stdcall"
> convention?  I can get both lines to work in my version of the DLL
> I explicitly use the __stdcall __export modifiers.  But I wanted to
> out your build with Visual Studio as opposed to mine with Turbo C++.
> -Marc

GMX startet Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein:
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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]