user561232
user561232

Reputation:

P/Invoke Fortran Dll causing unhandled exception when using intrinsic functions

Fortran Code

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# Code

    [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);
    }

Exception

Unhandled exception has occurred in a component in your application....

Unable to load DLL "TestingFortranDll.dll": The specific module could not be found. (Exception from HRESULT:0x8007007E)

This exception occurs only when I try to use implict functions like SQRT.

Upvotes: 0

Views: 375

Answers (1)

Zdeslav Vojkovic
Zdeslav Vojkovic

Reputation: 14591

This seems like the dll is missing some of its dependencies. Use Dependency Walker to find which dlls are missing

There is some information here about finding the Fortran redistributable files. You will need to supply them with your dll. For test, just copy them to the same directory and see whether it helps.

Upvotes: 1

Related Questions