[CoinMp] How to use CoinMP.Dll in Visual Basic (Excel)

Larry A. Taylor ltaylor at seas.ucla.edu
Fri Jun 29 15:46:39 EDT 2007


At 01:23 AM 6/29/2007, you wrote:
>I have tried to use CoinMP.Dll from Visual Basic. The follow declaration
>of function had created:
>
>Public Declare Function CoinInitSolver Lib "CoinMP.dll" (ByVal LicenseStr
>As String) As Long
>
>Then I have tried to call the function:
>     Dim s As String
>     s = Chr(0)
>     CoinInitSolver s
>But error "Bad Dll calling conversion" had happened... Why? The CoinMP.Dll
>was downloaded coin-or.org site...

What version of (MS) Visual Basic are you using? There have been significant
changes. You mention Excel? So, maybe it is Visual Basic for applications?

I have been trying some of the same things, but at least I got beyond this
point.

For strings, you have to know that C/C++ strings are different from anything
in Visual Basic. You will have to convert them from permanent, Unicode
system strings to arrays of system Byte before calling the dll.

(In addition, if your VB is version 6, or earlier as it appears to 
be, there have
been big changes in the Visual Basic language since then.)

The following is Visual Basic 2005:
>    <DllImport("CoinMP.dll")> _
>     Function CoinInitSolver(ByVal LicenseStr() As Byte) As Integer
>     End Function

>         Dim blnkStr(), nameStr() As Byte
>         blnkStr = string2ByteC("")
>         nameStr = string2ByteC("CoinMPTest")
>
>         CoinInitSolver(blnkStr)
>         hProb = CoinCreateProblem(nameStr)

The conversion routine I think I got from Microsoft somewhere


>     Function string2ByteC(ByVal instring As String) As Byte()
>         Dim i, n As Integer
>
>         ' construct byte array same length as input string
>         n = instring.Length
>         Dim s2b(n) As Byte ' one more than input for null term
>
>         ' convert each char in string to byte
>         ' Mid function is 1 based, but array ref is 0 based
>         For i = 1 To n
>             s2b(i - 1) = CByte(Asc(Mid(instring, i, 1)))
>         Next
>         s2b(n) = 0 ' C style null terminator
>
>         string2ByteC = s2b
>
>     End Function

Anyway, as I said, I can get that far. The big problem I had
was when I try to call CoinLoadProblem, because the C++ header
includes two C arrays of strings
>char** ColNames, char** RowNames);

and I haven't figured out how to create something like that or
get around it.

In C this is a multi-level array, and at the top level it is an array
of pointers. Managed code doesn't like pointers, it likes references,
and won't let you make an array of machine addresses (pointers).

I have not yet solved this problem. I have been working on a
wrapper for CoinMp.dll, but I haven't gotten it work, and I am
frustrated trying to get the right answers from Microsoft.

Let me know if you have a solution.

LAT 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/coinmp/attachments/20070629/43a3239c/attachment.html


More information about the CoinMp mailing list