[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 03:03:51 +0100

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 *)(cons
t void *,const void *)'

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

/* 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 
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 when
> I explicitly use the __stdcall __export modifiers.  But I wanted to test
> 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:

Attachment: test.mod
Description: Binary data

reply via email to

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