Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Fortran DLL does not work in EXCEL VBA

$
0
0

Hi,

I created a DLL file (testDLL.dll) to add two numbers in Fortran as follows:

SUBROUTINE addFunction(a, b, Sum)

!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE, ALIAS:"addFunction" :: addFunction

IMPLICIT NONE
REAL :: a, b, sum

sum = a + b

RETURN
END SUBROUTINE addFunction 

and then copied the DLL file in C:\Users\vb\AppData\Roaming\Microsoft\AddIns

when I try to use this DLL in EXCEL VBA as follows:

Public Declare PtrSafe Sub addFunction Lib "testDLL.dll" (a As Single, b As Single, abSum As Single)

Public Function addNumbers(a, b)

Dim sumNums As Single

Call addFunction(a, b, sumNums)
addNumbers = sumNums

End Function

It gives me #VALUE instead of the sum of two numbers in EXCEL. I debugged my code in VBA and it seems that it cannot find (or read) my dll file. My computer is a 64-bit machine and my EXCEL is 32-bit, so I generated a 32-bit DLL in Fortran to be compatible with my EXCEL. I really appreciate if anyone can help me to solve this error.     

Thanks


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>