I am new in Fortan and have a question regarding using make callback-functions available for the whole fortran-code.
I am writing on a interface which accesses a Fortran DLL from C#.
module csWrapper
interface
subroutine vdiTestFuncCllBak(inputValue, retValue)
INTEGER, INTENT(IN) :: inputValue
INTEGER, INTENT(INOUT) :: retValue
end subroutine
end interface
procedure(vdiTestFuncCllBak), pointer :: m_vdiTestFuncCllBak
end module csWrapper
module VdiFunctionRunnerMain
use csWrapper
implicit none
contains
integer function VdiFunctionRunner (XTGA, ARRAY_810, vdiCwertCllbak, vdiIwertCllbak, vdiRwertCllbak, vdiCwert2Cllbak, vdiIwert2Cllbak, vdiRwert2Cllbak, vdiErsterCllBak, vdiLetzterCllBak, vdiTestFuncCllBak)
!DEC$ ATTRIBUTES DLLEXPORT ::VdiFunctionRunner
!DEC$ ATTRIBUTES REFERENCE :: XTGA, ARRAY_810, vdiCwertCllbak, vdiIwertCllbak, vdiRwertCllbak, vdiCwert2Cllbak, vdiIwert2Cllbak, vdiRwert2Cllbak, vdiErsterCllBak, vdiLetzterCllBak, vdiTestFuncCllBak
implicit none
external vdiCwertCllbak, vdiIwertCllbak, vdiRwertCllbak, vdiCwert2Cllbak, vdiIwert2Cllbak, vdiRwert2Cllbak, vdiErsterCllBak, vdiLetzterCllBak, vdiTestFuncCllBak
!procedure(vdiErsterCllBak), pointer :: m_vdiErsterCllBak
CHARACTER (len=256) XTGA
CHARACTER (len=256) TGA, ARRAY_810(10), retValue, satzArt, satzArt2
CHARACTER (len=256) :: cWertCallBackRet
integer :: nrReturnValues = 1
m_vdiTestFuncCllBak => vdiTestFuncCllBak
call vdiTestFuncCllBak(nrReturnValues, nrReturnValues)
call m_vdiTestFuncCllBak(1, nrReturnValues)
VdiFunctionRunner = nrReturnValues
end function VdiFunctionRunner
end module VdiFunctionRunnerMain
Because the Fortran-code need the possibility to use some functions of the C#-code to, a pass two delegates to the Fortran-code (vdiCwertCllbak, vdiIwertCllbak).
This works quite well when they are used in the MainFunction, so the interfacing works so far.
Now it is needed, that the c#-functions must be available from other functions outside of the MainFunction and even in different modules.
I tried to use functionpointers to deal with this problem, but always get the following error when calling m_vdiTestFuncCllBak. Calling vdiTestFuncCllBak works without problems.
It is the same behaviour when initializing the pointer in the function or in an external module.
The following c# code is called:
private void vdiTestFunc(ref int inputValue, ref int retValue)
{
retValue = inputValue + 1;
return;
}
The problem is, that the references of inputValue and retValue are not set when using the funtionpointer.
Does someone had the same issue before and knows a possible solution or has a link with help? I haven't found information about that in my searches.
I am using the Intel 11 compiler.
Help is very much appreciated.