Interface 使Fortran中的其他函数/模块可以访问外部函数
我是Fortan新手,对整个fortran代码使用make回调函数有疑问 我在一个从C#访问Fortran DLL的接口上写 因为Fortran代码需要使用C#代码的一些函数来传递两个委托给Fortran代码(VDICWERTCLBAK,VDIIWERTCLBAK) 这在main函数中使用时效果很好,因此到目前为止接口工作正常 现在需要的是,c#-函数必须可以从main函数之外的其他函数,甚至在不同的模块中使用 我尝试使用函数指针来处理这个问题,但在调用m_vdiTestFuncCllBak时总是出现以下错误。调用vdiTestFuncCllBak不会出现问题 在函数或外部模块中初始化指针时,这是相同的行为 以下c#代码被称为:Interface 使Fortran中的其他函数/模块可以访问外部函数,interface,fortran95,Interface,Fortran95,我是Fortan新手,对整个fortran代码使用make回调函数有疑问 我在一个从C#访问Fortran DLL的接口上写 因为Fortran代码需要使用C#代码的一些函数来传递两个委托给Fortran代码(VDICWERTCLBAK,VDIIWERTCLBAK) 这在main函数中使用时效果很好,因此到目前为止接口工作正常 现在需要的是,c#-函数必须可以从main函数之外的其他函数,甚至在不同的模块中使用 我尝试使用函数指针来处理这个问题,但在调用m_vdiTestFuncCllBak时总
private void vdiTestFunc(ref int inputValue, ref int retValue)
{
retValue = inputValue + 1;
return;
}
问题是,在使用FunctionPointer时,没有设置inputValue和retValue的引用
是否有人曾经遇到过同样的问题,并且知道可能的解决方案,或者与帮助有联系?我在搜索中还没有找到有关这方面的信息
我正在使用英特尔11编译器
非常感谢您的帮助。一种快速而肮脏的方法是制作一个包含过程指针的模块:
module callback_module
procedure(),pointer::p
end module
integer function MainFunction(XTGA, ARRAY_810, vdiCwertCllbak, vdiIwertCllbak)
!DEC$ ATTRIBUTES DLLEXPORT ::MainFunction
!DEC$ ATTRIBUTES REFERENCE :: XTGA, ARRAY_810, vdiCwertCllbak, vdiIwertCllbak
use callback_module
implicit none
external vdiCwertCllbak, vdiIwertCllbak
integer :: nrReturnValues = 1
integer :: iWertCallBackRet = 12
satzArt = '710.10' // char(0)
p=>vdiIwertCllbak
call vdiIwertCllbak(satzArt, 1, 2, iWertCallBackRet)
MainFunction= nrReturnValues
end function MainFunction
integer function tga_810(xtga,array_810)
use callback_module
character(len=256) xtga,tga,array_810(4),s, caption, inputBox
call p('710' // char(0), 1, 2, retValue)
tga_810 = 1
end function tga_810
编辑:
访问冲突可能是因为指针没有关联的接口
module callback_module
interface
subroutine callback_sub(arg1,arg2,...)
!Declare all arguments as they appear in the actual callback routine
end subroutine
end interface
procedure(callback_sub),pointer::p
end module
您需要正确定义接口的过程参数
它也可能是由具有可选参数引起的。VDIIWERTCLBAK有选项吗?谢谢您的建议。我尝试使用functionspointers来实现这一点,但当我尝试访问函数指针时,得到了一个AccesViolationError。我将更新我的问题:)谢谢,我已经这样做了,我的testFunction的AccessViolationError现在已经修复,它只有2个整数参数。我想问题是,指针与接口没有关联。但是现在我得到了一个对象引用,而不是一个对象的实例。我会更新我的问题。谢谢你的帮助。不,我没有可选的参数。只有两个整数。恐怕我对C#不太熟悉,尤其是不太熟悉Fortran。希望其他人能看到这一点并给出答案。
module callback_module
interface
subroutine callback_sub(arg1,arg2,...)
!Declare all arguments as they appear in the actual callback routine
end subroutine
end interface
procedure(callback_sub),pointer::p
end module