Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28446 Discussions

Calling Intel Fortran DLL from Excel VBA...

jeffreyzalc
Beginner
376 Views
I had been using CVF 6.6 Pro to make a Fortran dll that I call from Excel VBA. Everything worked fine.
Upon building the dll using the Intel compiler, I find that when I call it from Excel VBA the arguments are passed correctly (I write them to file immediately upon entering the Fortran routine), the Fortran code executes properly (again, I dump all variables to file just before the end of the routine). However, the code never returns from the dll. That is, if in the VBA I have Msgbox calls before and after the subroutine call for the dll, I never see the second Msgbox.
This behavior occurs even if I make a very simple dll that takes two double precision arguments, say x and y, and returns y= 2.0*x. The value of x will be received correctly in the Fortran, y will be calculated properly, but the answer and control never come back from the Fortran.
None of these problems ever occur with CVF.
0 Kudos
2 Replies
Steven_L_Intel1
Employee
376 Views
Make sure that either you build the DLL with the /iface:CVF option (applied by default when you convert from a CVF project) or that you specify the STDCALL and REFERENCE attributes for the DLL routine. If you get the calling convention wrong, you can see exactly this sort of problem.

I have done several example programs of Excel calling Intel Fortran DLLs and never had a problem.
0 Kudos
martin_erwin
Beginner
376 Views

First, thank's for responding,

After some hours reading manuals and doing tries and errors I suddenly ended up with a now constantly working debugger but still do not know why...

Regarding toyour question: My Excel is in german (Menues and Worksheet-Function in German, VBA is as usual in English)

Now I can debug as I want. I don't know if it is important, but now I declared all my local Variables and Constants as Public ina privatmodule where I declared the dll-Library and its functions. They have originally been on the Codetable that refers to Worksheet1. There a Togglebutton_Click-Event calls the fortranroutine.

With Breakpoints in CV-Fortran and Go-Command (F5) and Breakpoints in Excel-VBA with (F8)-Debugging I now can trace through.

Until now I just managed to exchange Integer-Variables. Real-, Double-Vars, Arrays and Strings are next goals for tomorrow. Let's see.

It still is interesting for me to understand, what went wrong and if I can correct any program-options, because now I cannot exclude that problems will arise again.

Martin

0 Kudos
Reply