Re: Problems calling Fortran DLL from VBA



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.
.



Relevant Pages

  • Re: VBA and VSTO
    ... If you compile in VB6 with Global MultiUse than all you have to do is set a reference in Excel to your dll via Tools, References and you can access your functions in the dll directly. ... You will have to register the dll as well with Windows with Regsvr32, but that can be done quite simply in VBA. ...
    (microsoft.public.excel.programming)
  • Re: Function to read text file; find string; delete same before import
    ... You can't compile into a dll with VBA, but I believe with FreeBasic you can and it is free. ... Dim FileNum As Long ...
    (microsoft.public.excel.programming)
  • Problem trying to make my DLL callback a VBA function with paramet
    ... I am able to call my DLL functions from VBA without any problems. ... EXTERNC DLLAPI DWORD WINAPI DllCBInit; ... EXTERNC DLLAPI void WINAPI DllCBTest1; ...
    (microsoft.public.excel.programming)
  • Re: Function to read text file; find string; delete same before import
    ... All I want to do is compile my VBA code into ... project" into a .DLL which is much more "secure" than a VBProject ... Are there any alternate choices to secure VBA? ... Dim FileNum As Long ...
    (microsoft.public.excel.programming)
  • Re: Class properties or function?
    ... You are assigning a variable named formTag with the value of your form's Tag property, but I don't see any definition for the variable formTag. ... But the property value that you are trying to reference from your Word VBA is based on the variable tempTag. ... You are using the myClass property to access the DLL, but you are not saving a reference to the object that you have created. ... Public Property Let myTag ...
    (microsoft.public.vb.general.discussion)