Re: Problems calling Fortran DLL from VBA
- From: Craig Powers <craig.powers@xxxxxxxxxxxxxxx>
- Date: Wed, 29 Oct 2008 17:22:19 -0400
rcl2884 wrote:
I am in trying to figure out how to use a DLL created in Fortran in
VBA. I have a very simple Fortran procedure that I have compiled into
a DLL. I can succesfully call this DLL from another Fortran procedure.
I would like to access the DLL from VBA. I use the following protocol
to define the function within the VBA (in Excel)
Declare Function MyCalc Lib "test.DLL" Alias "_calc@12" _
(ByRef n1 As Long, ByRef n2 As Long, ByRef n3 As Long)
The decorated name suggests that it was build using the stdcall calling convention, which is the right thing to do. I trust you've looked at the mixed language documentation for your compiler to make sure that any other calling convention issues have been addressed.
I have used this exact protocol successfully for DLL's created in C++
and so I know the protocol is right.
The error message that I get is "file not found: Test.DLL"
The DLL is in the same folder as the excel. I have also tried using
the full path and also putting the DLL in the windows/system32 folder,
but to no avail.
VB/VBA is very unhelpful when there are DLL errors. In particular, it will give you "file not found" errors that imply an inability to find YOUR dll, when the actual problem is a DEPENDENCY dll. For your specific case, a potential issue is that depending on your flags when you built the dll, it may depend on a Fortran runtime that is not part of the regular library search path.
Probably the easiest way to track this down is to try loading the dll using the Dependency Walker.
http://www.dependencywalker.com/
Dependency Walker will tell you which other libraries your dll requires in order to load, and it will flag the ones that it can't find. I'm fairly certain that the "file not found" message does mean that the problem is a file not found error, though probably not actually Test.DLL.
I have tried registering the DLL using regsvr32 and get the following
message
"Test.DLL was loaded but the DLLregister Entry Point was not found"
regsvr32 only applies for COM DLLs, which I presume is not what you are using.
.
- Follow-Ups:
- Re: Problems calling Fortran DLL from VBA
- From: e p chandler
- Re: Problems calling Fortran DLL from VBA
- References:
- Problems calling Fortran DLL from VBA
- From: rcl2884
- Problems calling Fortran DLL from VBA
- Prev by Date: Re: how to specify unknown number of format before hand
- Next by Date: Re: Fortran 2003 Handbook
- Previous by thread: Problems calling Fortran DLL from VBA
- Next by thread: Re: Problems calling Fortran DLL from VBA
- Index(es):
Relevant Pages
|