1

I want to run fortran dll in C# application.

I have tried to do so using DllImport from System.Runtime.InteropServices. Unable to execute the subroutine from the dll as receving "System.BadImagFormatException".

Following is the Fortran sample Code, cmdwmaindll is the dll which I want to call in C#

program CallDll
    !DEC$ ATTRIBUTES::Cndwmaindll
    implicit none

    ! Variables
      character*4 cond1in, cond2in, brnamein
      real cgpmin, ecwtin, lcwtin, condffin, wbrinein,thr1in, thr2in
      real tsat1in, tsat2in, dt1in, dt2in
      character*3 hconfigin
      real ctn1out, ctn2out,lt1out, lt2out,WPDFtout

      cond1in = 'V058'
      cond2in = cond1in
      cgpmin = 125.00
      ecwtin = 85.00
      lcwtin = 0.00
      condffin = 0.00025
      wbrinein = 0.0
      brnamein = '00'
      thr1in = 31.4
      thr2in = 31.4
      tsat1in = 105.8
      tsat2in = 105.5
      dt1in = 160.0
      dt2in = 160.0
      hconfigin = 'STD'
      call Cndwmaindll(cond1in, cond2in, cgpmin, ecwtin, lcwtin, &
                       condffin, brnamein,wbrinein,thr1in, &
                       thr2in,tsat1in,tsat2in,dt1in,dt2in, &
                       hconfigin, &
                       ctn1out,ctn2out,lt1out,lt2out,WPDFTout)
      Write(*,*) ctn1out, ctn2out, lt1out, lt2out, WPDFTout
    end program CallDll

C# Code Snippet

[DllImport(@"Cndwmaindll.dll", CharSet = CharSet.Ansi,CallingConvention = CallingConvention.Cdecl)]
        public static extern void Cndwmaindll([In] char[] cond1in, [In]char[] cond2in, ref float cgpmin, ref float ecwtin, ref float lcwtin, ref float condffin,
          ref string brnamein, ref float wbrinein, ref float thr1in, ref float thr2in, ref float tsat1in, ref float tsat2in, ref float dt1in, ref float dt2in, [In] char[] hconfigin,
         ref float ctn1out, ref float ctn2out, ref float lt1out, ref float lt2out, ref float WPDFtout);

Tatipaka
  • 190
  • 2
  • 13

0 Answers0