Calling Conventions in Fortran

Calling Conventions in Fortran

Community Admin's picture

Hi!

Ich try to write a dll in Fortran that exports function having strings as parameters to be used in a Fortran program. But I doesn't work!!! Can somebody give me an example of this? Thank you!
Below are parts of my Fortran code. Where is the error?

interface 
 
logical function LoadInterActionParameter(Anco, Ansteu, & 
     &	AMixRule, Atblock, k, la, l, s, kkap, kep, Aexdataname) 
!DEC$ IF DEFINED(_X86_) 
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_LOADINTERACTIONPARAMETER@48' :: LOADINTERACTIONPARAMETER 
!DEC$ ELSE 
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'LOADINTERACTIONPARAMETER' :: LOADINTERACTIONPARAMETER 
!DEC$ ENDIF 
!DEC$ ATTRIBUTES REFERENCE::Aexdataname, Anco, ansteu 
DEC$ ATTRIBUTES REFERENCE::AMixRule, Atblock 
!DEC$ ATTRIBUTES REFERENCE::k, la, l, s, kkap, kep 
character*(*) AExdataName 
integer Ansteu, AMixRule, Atblock, Anco 
double precision k(10,10), la(10,10), l(10,10) 
double precision s(10,10), kkap(10,10), kep(10,10) 
end function 
end interface 
 
---------------------------- 
 
logical function LoadInterActionParameter(Anco, Ansteu, AMixRule, Atblock,    & 
&                 k, la, l, s, kkap, kep, Aexdataname) 
!DEC$ ATTRIBUTES DLLEXPORT::LOADINTERACTIONPARAMETER 
!DEC$ ATTRIBUTES REFERENCE::Aexdataname, Anco, ansteu, AMixRule, Atblock 
!DEC$ ATTRIBUTES REFERENCE::k, la, l, s, kkap, kep 
 
implicit none 
 
integer Ansteu, AMixRule, Atblock 
integer xnsteu, xmixrule, xkt, Anco 
double precision k(10,10), la(10,10), l(10,10) 
double precision s(10,10), kkap(10,10), kep(10,10) 
 
character*(*) Aexdataname 
 
  LoadInterActionParameter = .false. 
 
! Body  
 
end function
3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Jugoslav Dujic's picture

Please never use the term "doesn't work" (especially not followed by !!!). Doesn't compile? Doesn't link? Causes your application to crash? Causes your computer to burn?.

With combination STDCALL+REFERENCE on string arguments, length of
the string is not passed. Thus, you have to "hard-code" string length in the callee, i.e. CHARACTER(LEN=50).

If you intend to use it only from Fortran caller, STDCALL, REFERENCE and ALIAS are not necessary (but do no harm as long as they're consistent). In the actual case, if you omit STDCALL, your declaration of character variable could retain standard (LEN=*).

Jugoslav

Jugoslav www.xeffort.com
Community Admin's picture

Thank you for your answer, Jugoslav!

I could solve my problem with giving the length explicitly (Len = 50 etc.). Can I find somewhere a WORKING example of how to use functions with strings from a DLL in Fortran?

Thank you!
Stan

Login to leave a comment.