MPBA for VBA7 64位?

时间:2017-07-03 03:13:11

标签: vba excel-vba mpir excel

我可以用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。我有64位Excel与VBA7,我想用它来调用大型整数函数的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并在64位VBA7中使用生成的dll。

0 个答案:

没有答案