Fortran 代码
FUNCTION ComputeSquareRoot(inputValue)
IMPLICIT NONE
!DEC$ ATTRIBUTES ALIAS:'ComputeSquareRoot' :: ComputeSquareRoot
!DEC$ ATTRIBUTES DLLEXPORT :: ComputeSquareRoot
REAL*8 :: inputValue
REAL*8 :: ComputeSquareRoot
ComputeSquareRoot = SQRT(inputValue)
RETURN
END FUNCTION
C# 代码
[DllImport("TestingFortranDll.dll", CallingConvention = CallingConvention.Cdecl)]
static extern double ComputeSquareRoot(ref double inputValue);
/// <summary>
/// Wrapper method for ComputeSquareRoot.
/// </summary>
/// <returns></returns>
public static double CallingComputeSquareRoot()
{
var inputValue = 100.0;
return ComputeSquareRoot(ref inputValue);
}
例外
在您的应用程序的组件中发生未处理的异常......
无法加载 DLL“TestingFortranDll.dll”:找不到特定模块。(HRESULT 例外:0x8007007E)
仅当我尝试使用 SQRT 等隐式函数时才会发生此异常。