我能够使用 MSYS2 和 Mingw-w64 构建 MPIR
./configure ABI=64 --prefix=/MPIR/MPIRinstall --build=skylakeavx-w64-mingw64 --disable-static --enable-shared --with-yasm=/usr/bin/yasm-1.3.0-win64.exe
导致 libmpir-23.dll。我有带有 VBA7 的 64 位 Excel,我想用它来调用大整数函数的 dll。我认为这应该是可能的,因为 64 位版本的 MPIR 和 VBA 应该使用 fastcall,并且 MPIR 大整数类型的组件已经很好地对齐到四个或八个字节块。但是,在运行初步测试以尝试设置和读取 MPIR 大整数时,我没有得到预期的结果:
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
结果L
是 0,而不是 525,在第一次诊断时,mpz_get_str(es, p, f)
是一个空字符串,并且es
没有从"jjjj"
. 在最后一次诊断中,L
不是 12,而是 100977072。
我没有 VS,也没有任何构建 dll 的经验。我在网上找到的所有关于 MPIR 或 GMP 的答案都与 32 位版本的 VBA 和 dll 相关,而且它们似乎不适用于 64 位的情况。
我想知道是否可以使用 MSYS2 构建 MPIR 并在 VBA7 64 位中使用生成的 dll。