Re: Problems calling Fortran DLL from VBA



Thanks to the both of you for your interest.

I do have mixed language documentation, and the Absift documentation
and so I tried to make sure I did everything right. As I mentioned,
this is a very simple test program.

GLOBAL DEFINE
PARAMETER (iDLL_PROCESS_DETACH = 0)
PARAMETER (iDLL_PROCESS_ATTACH = 1)
PARAMETER (iDLL_THREAD_ATTACH = 2)
PARAMETER (iDLL_THREAD_DETACH = 3)
END
C-----------------------------------------------------------------------
STDCALL FUNCTION DllMain(HINST, REASON, RESERVED)
INTEGER*4 DllMain
INTEGER*4 HINST, REASON, RESERVED
VALUE HINST, REASON, RESERVED
DllMain = 1
RETURN
END
C-----------------------------------------------------------------------
stdcall subroutine Calc(I,J,K)
integer*4 I,J,K
K = I*J
return
end

I did run Dependency Walker, but I don't really understand the message

Warning: At least one module has an unresolved import due to a missing
export function in a delay-load dependent module.

There are four DLL's that are highlighted to the left in the
WalkerDependency window (ADVAPI32, SHLWAPI, USER32, MPR).

Do you have any suggestions? ... and pardon my ignorance, but this all
seems somewhat mysterious to me.

Thanks again,
Rick




On Oct 30, 10:21 am, e p chandler <e...@xxxxxxxx> wrote:
On Oct 29, 5:22 pm, Craig Powers <craig.pow...@xxxxxxxxxxxxxxx> wrote:





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.

A different possibility is that the name of the called routine is not
exported from the DLL. Sorry, I don't have Absoft. Its web site has
voluminous documentation, but it was not obvious to me how to specify
what in DVF/CVF/IVF would be

!DEC$ ATTRIBUTES DLLEXPORT :: calc

To the OP: Why not list (at least the relevant part of) your program
and the commands you used to compile it so we don't have to guess?

-- e- Hide quoted text -

- Show quoted text -

.



Relevant Pages

  • Re: moving a AFX DLL from VS 2003 to either 2005 or 2008 causes issue at loadlibrary
    ... to make the same DLL work after changing the ... Even though its told in the compiler options to link MFC staticly, ... Is it a direct dependency of your DLL? ... have linked with some other static libraries that are dependent on the MFC ...
    (microsoft.public.vc.mfc)
  • LoadLibrary problem
    ... I am experiencing a strange problem with an ActiveX dll that I am building ... This dll built fine with evc3. ... I added the /Gy compiler option to resolve the ... I have run dependency walker on the dll and everything is found, ...
    (microsoft.public.pocketpc.developer)
  • LoadLibrary problem
    ... I am experiencing a strange problem with an ActiveX dll that I am building ... This dll built fine with evc3. ... I added the /Gy compiler option to resolve the ... I have run dependency walker on the dll and everything is found, ...
    (microsoft.public.pocketpc)
  • LoadLibrary problem
    ... I am experiencing a strange problem with an ActiveX dll that I am building ... This dll built fine with evc3. ... I added the /Gy compiler option to resolve the ... I have run dependency walker on the dll and everything is found, ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Release build exe has MFC71D.dll, MSVCR71D.dll and MSVCP71d.dll
    ... I am 100%sure that my dll is not having any dependency on the ... My preprocessor settings have a macro called _DEBUG which is going to ... same directory where my exe is placed. ...
    (microsoft.public.vc.mfc)