Re: Problems calling Fortran DLL from VBA



On Oct 30, 4:19 pm, rcl2884 <rleav...@xxxxxxxxxxxxxxxx> wrote:
Thanks again for your interest. I was definitely a dummy on the
Function/Sub Routine issue. I had copied a declare function from
another call to a C++ DLL that I know works, but neglected to change
Function to SUB.

Just to be consistent with your example, I changed everything to be a
function.

The Fortran:

      stdcall function Test(I,J)
      integer*4 I,J,test
      test = I-J
      return
      end

I did not include the export line you suggest

!dec$ attributes dllexport, stdcall, reference, alias:'isub2' :: isub2

The line starts with ! so it's a comment unless the compiler has an
extension to standard behavior which gives it some other meaning.

since that was the prior protocol. The absoft documentation for 10.1
suggests that export is done automatically as part of the compile, and
I have followed their suggested syntax on the function. I did verify
through WalkerDependency that the function _test@8 has been properly
exported. I also get another exported function _DllMain@12 which I do
not understand.

DllMain is the initialization entry point to your DLL. You set its
value to 1 before which does equal "success". In my experience this
routine is automaticly written for you in the process of creating your
DLL.


The VBA declare statement

Declare Function MyTest Lib "test.DLL" Alias "_test@8" (n1 As Long, n2
As Long) As Long

The VBA test routine

Sub Testing()
Dim n1 As Long
Dim n2 As Long
Dim n3 As Long
n3 = MyTest(n1, n2)
End Sub

... and yet, I still get the same error.

Craig has covered the problem with possible external dependencies.
Everything listed was a standard windows library and dll, so I don't
see the problem there.

One other possibility is that the test.dll is not in the right
directory (folder). I listed a number of places where test.dll might
have to be located. IIRC Word is more strict than Excel. But same
directory as the workbook/document, Current user's Documents or My
Documents folder, one of the other directories listed on your PATH,
\Windows\system32, \Windows\system, \WinNT\system32, etc. depending on
your vesrsion of Windows.

I have a call into Absoft to
see if they can help figure out what I am not doing right,

Good. Have you checked to see if this is covered in their user formus?

but if you see anything obvious...

Nothing obvious.

See a discussion in their user forms

http://absoft.absoft.com/newforums/index.php?PHPSESSID=7fe653d95107ce50c4fb47d0d9b5028b&topic=103.0

There, Jeremy (tech support) says that

af77mathdll.dll
af90mathdll.dll
afiodll.dll

are the 3 possible 3 dlls that might be needed.

Also, one user says "software documentation always stops just before
the answers to the difficult questions" and asks for expansion of
Appendix F.

Finally, Jeremy provides a link http://www.absoft.com/electronicdelivery/windows-pro-10.1/vbDLLv10.1.zip
to a VB (compiled not VBA) program and a Fortran dll. It's a
subroutine rather than a function.

Note that the discussion of where to put the DLL is relative to a
compiled VB application, not a document invoking VBA.

Hope this helps. From what little I've seen - I'm not a customer -
they could strengthen their documentation.

-- e






.



Relevant Pages