首页 > 解决方案 > 如何使用 C# 调用 Fortran DLL 函数

问题描述

我有 Fortran DLL,其中包含以下代码。

想要使用 C# 代码调用此 DLL 函数。

我已经尝试使用以下代码调用此 DLL。

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

这是DLL函数结构。

  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)

标签: c#dllfortran

解决方案


推荐阅读