我想从一个Fortran编译库导入函数的函数形式的签名,我有机会在C:的PInvoke从FORTRAN语言C#
typedef void (__stdcall *fp_SUBLTdllTYPE)(double &,double *,double &,long &,char*,long);
我的C#代码如下:
//(long &,char*,char*,char*,long &,char*,long ,long ,long ,long);
[DllImport(@"C:\Program Files\REFPROP\refprop.dll",
CallingConvention=CallingConvention.StdCall,
CharSet = CharSet.Auto,
EntryPoint = "SETUPdll")
]
public static extern void Setup([In] long nc,[In]
[MarshalAs(UnmanagedType.LPStr)] StringBuilder hfiles,
[In] [MarshalAs(UnmanagedType.LPStr)] StringBuilder hfmix,
[In] [MarshalAs(UnmanagedType.LPStr)] StringBuilder hrf,
[In,Out] long ierr, [Out] [MarshalAs(UnmanagedType.LPStr)] StringBuilder herr,long l1, long l2, long l3,long l4);
和FORTRAN定义是:
subroutine SETUP (nc,hfiles,hfmix,hrf,ierr,herr)
implicit double precision (a-h,o-z)
implicit integer (i-k,m,n)
implicit logical (l)
c
cDEC$ ATTRIBUTES DLLEXPORT :: SETUP
c dll_export SETUP
c
parameter (ncmax=20) !max number of components in mixture
parameter (nrefmx=10) !max number of fluids for transport ECS
parameter (n0=-ncmax-nrefmx,nx=ncmax)
parameter (nrf0=n0) !lower limit for transport ref fluid arrays
parameter (nrefluids=4) ! numb
的问题是,我没有获得一个Fortran组合物1勒勒和我的fortran几乎是零。
当我打电话从C#代码的功能:
long ierr=0;
long i = 2;
StringBuilder herr=new StringBuilder("");
Setup(i, new StringBuilder("R410a.mix"), new StringBuilder("hmx.bnc"), new StringBuilder("DEF"), ierr, herr, refpropcharlength * ncmax, refpropcharlength,
lengthofreference, errormessagelength);
我得到以下错误:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
谁能帮助我?
我不知道Fortran中的字符串。但是,你的整数是错误的。在Windows上的C中,“long”是32位。在C#中使用'int'来匹配它。 –