Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29284 Discussions

How to use a fortran dll from a fortran application using VS .Net

cdpcapital
Beginner
742 Views
Hello,

I am unable to run this little application:

!!!!!!!!! Program!!!!!!!!!!!!!!!!!
program fortranTest2
use dlltest
implicit none


REAL(8) :: n
call returnOne(n)


end program fortranTest2
!!!!!!!!! DLL !!!!!!!!!!!!!!!!!!!!!
subroutine returnOne(n)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS :'returnOne' :: returnOne
REAL(8) , intent(out) :: n
n = 1.0
end subroutine returnOne

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
It tells me the following:
Error: Error in opening the Library module file. [DLLTEST]

What I tried:

**1**
I have added the dll directory in both
Libraries and Includes

by clicking on :
Tools->options->Intel Fortran

**2**
I have also tried to copy the dll in the
debug and ../debug directories.

**3**
And I have change the library type to see if it helped.
In Solution Explorer->DllTest ->Properties->Libraries
the library type is Single-Threaded

*************************************

Any suggestion on what i should do next ?

Thanks for your help.
0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
742 Views
For the start, remove the "use dlltest" statement. It has nothing to do with the dlls whatsoever. Please Read the Fine Manual.
0 Kudos
cdpcapital
Beginner
742 Views
Thanks for your comment, but it was not of great help to me.

Could you tell me what manual ? I looked at the fortran user's guide and was not able to find the answer to that question.

Thanks again.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
742 Views
Well, what happens if you remove USE DllTest statement? You certainly won't get the same error.

Look up USE and MODULE keywords in Language Reference chapter they're not related with dlls whatsoever.

To use a dll, at minimum you should link the .exe with dllname.lib and export the routines via !DEC$ATTRIBUTES DLLEXPORT or .def file.

However, since you use:

!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS :'returnOne' :: returnOne

you have to provide an explicit interface for the dll, as it doesn't use the default calling conventions. So, you need an interface block, and you might define it in MODULE DllTest; instead of removing USE DllTest, write the module, in a separate .f90 file or before the PROGRAM, like this:

MODULE DllTest

INTERFACE
subroutine returnOne(n)
!DEC$ ATTRIBUTES DLLIMPORT, STDCALL, REFERENCE, ALIAS :'returnOne' :: returnOne
REAL(8) , intent(out) :: n
end subroutine returnOne
END INTERFACE

END MODULE


In this way, you will assure that the .exe "knows" how to call returnOne correctly.
0 Kudos
Reply