Excel VBA fails to correctly send arguments to Fortran DLL if argument list has changed, unless I change the DLL file name

I have a Fortran DLL (made using one of the latest Intel oneAPI IFORT compilers) and linked in Visual Studio 2019. One of the entry points contains an argument list of a mixture of Integer4 (Long in VBA) scalars and Real8 (Double in VBA) arrays. I call the function from Excel VBA using a Declaration like this (simplified to make it easy to follow):

Declare PtrSafe Function GetCatalyst Lib "myDll.dll" Alias "#3" (arg1 As Long, arg2 as Long, arg3 As Double, arg4 As Long, arg5 as Long, arg6 As Double) As LongPtr

Where arg1, arg2, arg4, arg5 are just scalar Long values, and arg3 and arg6 are Double arrays with length defined by one of the Long arguments e.g. arg3 is Double(1 to arg2). There are more like 20 arguments, but they follow this pattern.

The Excel call looks something like:

Dim arg1 as Long, arg2 as Long, arg3() as Double
Dim arg4 as Long, arg5 as Long, arg6() as Double

ReDim arg3(1 to arg2)
ReDim arg6(1 to arg5)

'< Some code to make sure the DLL is loaded using LoadLibrary happens here>

' Actual call here
Dim result as Long
result = GetCatalyst(arg1, arg2, arg3(1), arg4, arg5, arg6(1))

This all works fine, all the arguments are properly dimensioned in VBA to match the underlying function in Fortran, BUT then we tried adding another trio of arguments in the middle of the block of arguments, following the same pattern (another Long, Long and Double array). After this, the last three arguments in the list received junk values in the Fortran call, despite VBA apparently passing the correctly initialised values in.

Obviously we checked (and double, even triple checked) the new arguments are properly included in the Fortran (and this had built correctly with the expected compiler-generated interface definition) and that the VBA Declaration AND function call had both correctly been adapted to accommodate the new arguments. We even made a test Fortran application to load and call the DLL and this worked fine.

Finally, we tried loading the DLL function from the function NAME instead of the Ordinal number (“GETCATALYST” instead of “#3”) and this worked. We also tried compiling with a new (previously unused) ordinal number #17 and this also worked. Finally, we tried renaming the compiled DLL and loading this with the same original ordinal of #3, which also worked.

Does anyone know how VBA loads ordinal aliases for external DLL calls? It seems that it somehow caches the ordinal alias and shape/size of the arguments for that function somewhere, and only clears it when you supply a new file name for the DLL? We cannot work out what is going wrong, but it seems to be an Excel VBA issue, and seems to be specifically around using ordinal aliases for Fortran DLL calls.

Excel version is o365 build 2407.

Update: based on feedback (thanks!) I should clarify that the erroneous behaviour (junk arguments being passed from VBA into Fortran) persists even after a full machine restart, so it does not look like a per-session cache of the DLL entry point, but something more persistent.

9

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật