Call fortran dll from C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • libishkb
    New Member
    • Mar 2010
    • 6

    Call fortran dll from C#

    I am trying to call a fortran dll from c# code. But i get the following error message.An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B). Could any one please tell me where I am going wrong? The codes are given below.

    Fortran code

    Code:
    !  lwing.f90 
    !
    !  FUNCTIONS/SUBROUTINES exported from lwing.dll:
    !  lwing - subroutine 
    !
    ! Expose subroutine lwing to users of this DLL
      !
      !DEC$ ATTRIBUTES DLLEXPORT::lwing
    
      ! Variables
    SUBROUTINE lwing(span,dfuse,lenw)
    !-------------------------------------------------------------------
    ! This subroutine calculates the wing length in cantilever position
    
    !Input arguments: span- wing span
    !                 dfuse- Fuselage diameter
    !Output Arguments: lenw- Length of wing in cantilever position
    !-------------------------------------------------------------------
    IMPLICIT NONE
    REAL, INTENT(IN)::dfuse,span
    REAL, INTENT(OUT)::lenw
    
    
    lenw=(span-dfuse)/2;
    
    END SUBROUTINE lwing

    C# Code
    Code:
    namespace ggg
    {
        public class Model
        {
            [DllImport("lwing.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Winapi)] /* Import from DLL, the C# compiler provides a rudimentry check of the signature */
            public static extern void lwing(ref double span,ref double dfuse,ref double lenw);
            static void Main()
            {
                double a = 1;
                double b = 1;
                double c = 1;
                lwing(ref a,ref b,ref c);
            }
        }
    }
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Try getting rid of this section:
    CallingConventi on = CallingConventi on.Winapi

    Comment

    • libishkb
      New Member
      • Mar 2010
      • 6

      #3
      Problem solved

      I changed the 'Platform Target' from the properties of my C# project from 'AnyCPU' to 'x86'.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Did that turn out to be the solution?

        Comment

        • libishkb
          New Member
          • Mar 2010
          • 6

          #5
          yes strangely it was....

          Comment

          Working...