1

I am able to build MPIR with MSYS2 and Mingw-w64 with

./configure ABI=64 --prefix=/MPIR/MPIRinstall --build=skylakeavx-w64-mingw64 --disable-static --enable-shared --with-yasm=/usr/bin/yasm-1.3.0-win64.exe

resulting in libmpir-23.dll. I have 64-bit Excel with VBA7 which I want to use to call the dll for large integer functions. I think this should be possible as the 64-bit versions of MPIR and VBA should use fastcall, and the components of the MPIR large integer type are already well-aligned to either four or eight byte blocks. However, I am not getting the results expected in running a preliminary test to try to set and read a MPIR large integer:

Public Type vba_mpz
alloc As Long
size As Long
ptr As LongPtr
End Type

Public Type vba_mpq
num As vba_mpz
den As vba_mpz
End Type

Public Type vba_mpf
prec As Long
size As Long
exp As Long
ptr As LongPtr
End Type


Public Declare PtrSafe Sub mpz_init Lib "C:\\MPIR\mpir-3.0.0\mpir-3.0.0\.libs\libmpir-23.dll" Alias "__gmpz_init" (ByRef j As vba_mpz)

Public Declare PtrSafe Sub mpz_clear Lib "C:\\MPIR\mpir-3.0.0\mpir-3.0.0\.libs\libmpir-23.dll" Alias "__gmpz_clear" (ByRef j As vba_mpz)

Public Declare PtrSafe Sub mpz_set_str Lib "C:\\MPIR\mpir-3.0.0\mpir-3.0.0\.libs\libmpir-23.dll" Alias "__gmpz_set_str" (ByRef j As vba_mpz, ByVal s As String, ByRef b As Long)

Public Declare PtrSafe Function mpz_get_str Lib "C:\\MPIR\mpir-3.0.0\mpir-3.0.0\.libs\libmpir-23.dll" Alias "__gmpz_get_str" (ByVal s As String, ByRef b As Long, ByRef j As vba_mpz) As String

Public Declare PtrSafe Sub mpz_set_si Lib "C:\\MPIR\mpir-3.0.0\mpir-3.0.0\.libs\libmpir-23.dll" Alias "__gmpz_set_si" (ByRef j As vba_mpz, k As LongLong)

Public Declare PtrSafe Function mpz_get_si Lib "C:\\MPIR\mpir-3.0.0\mpir-3.0.0\.libs\libmpir-23.dll" Alias "__gmpz_get_si" (ByRef j As vba_mpz) As LongLong

 Sub Main()

 Dim f As vba_mpz
 Dim es As String
 Dim p, q, r As Long
 Dim L As LongLong
 p = 10
 mpz_init f
es = "525"
Call mpz_set_str(f, es, p)
L = mpz_get_si(f)
es = "jjjj"
MsgBox "Int from string:" & L
MsgBox "String from string:" & mpz_get_str(es, p, f)
MsgBox "String2 from string:" & es
L = 12
Call mpz_set_si(f, L)
L = mpz_get_si(f)
MsgBox "Int from int:" & L
mpz_clear f

End Sub

The results are L is 0, not 525, at the first diagnostic, mpz_get_str(es, p, f) is an empty string, and es has not been altered from "jjjj". On the last diagnostic, L is not 12, but rather 100977072.

I don't have VS, and I don't have any prior experience building dll's. All the answers I've been able to find online about MPIR or GMP relate to 32-bit versions of VBA and the dll, and they don't appear to apply to the 64-bit case.

I would like to know whether it is possible to build MPIR with MSYS2 and use the resulting dll in VBA7 64-bit.

Community
  • 1
  • 1
  • My Excel version is 2010. Oddly, MS has documentation for 2013 (https://msdn.microsoft.com/en-us/library/bb687915(v=office.15).aspx) and 2007, but not 2010. – Chris Staffa Jul 07 '17 at 19:02

0 Answers0