主题:新人求助:Fortran与C#之间的调用
各位好,我是个Fortran新人,在维护一个Fortran的计算程序,老板让做个界面并选了C#来实现
于是当我在用C#调用Fortran dll时,把C#的int传进去,报溢出异常,我想把输入值print出来,却发现每次print的int还会变,我不知道问题出在哪了,大家谁能帮忙分析一下啊,鄙人在此多谢了
C#代码如下:
[DllImport(@"TestF.dll",
SetLastError = true, CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall)]
public static extern void Cpm(ref int Ndir, ref char[] dirIn);
int iResult = 0;
string notes = "";
int iLen = 0;
string path = "D:\\input\\";
char[] cPath = path.ToCharArray();
try
{
iLen = cPath.Length;
CutPre(ref iLen, ref cPath);
iResult = 1;
notes = "Successful!";
}
……//以下略去
以下是Fortran部分代码
Subroutine Cpm(Ndir,dirIn)
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,ALIAS:'_Cpm@8' :: Cpm
!DEC$ ATTRIBUTES VALUE:: Ndir
!DEC$ ATTRIBUTES REFERENCE:: dirIn
Use ModUnit
Use ModGlobal,only : Rd1,Vd1,Td1,TT0sjs,A2R,R2A,pi,DefUnit,Nforce
Use ModTime
Use ModInput
Use ModData,only : DefTN,WData,DataRelease,DataSun,DefPV2
Use ModPerturbation,only : SatParamt,DefParamt
implicit none
INTEGER(4) :: Ndir
CHARACTER(Ndir) :: dirIn
Print *,"Input Success! Your input are :"
Print *,Ndir
Print *,dirIn
于是当我在用C#调用Fortran dll时,把C#的int传进去,报溢出异常,我想把输入值print出来,却发现每次print的int还会变,我不知道问题出在哪了,大家谁能帮忙分析一下啊,鄙人在此多谢了
C#代码如下:
[DllImport(@"TestF.dll",
SetLastError = true, CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall)]
public static extern void Cpm(ref int Ndir, ref char[] dirIn);
int iResult = 0;
string notes = "";
int iLen = 0;
string path = "D:\\input\\";
char[] cPath = path.ToCharArray();
try
{
iLen = cPath.Length;
CutPre(ref iLen, ref cPath);
iResult = 1;
notes = "Successful!";
}
……//以下略去
以下是Fortran部分代码
Subroutine Cpm(Ndir,dirIn)
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,ALIAS:'_Cpm@8' :: Cpm
!DEC$ ATTRIBUTES VALUE:: Ndir
!DEC$ ATTRIBUTES REFERENCE:: dirIn
Use ModUnit
Use ModGlobal,only : Rd1,Vd1,Td1,TT0sjs,A2R,R2A,pi,DefUnit,Nforce
Use ModTime
Use ModInput
Use ModData,only : DefTN,WData,DataRelease,DataSun,DefPV2
Use ModPerturbation,only : SatParamt,DefParamt
implicit none
INTEGER(4) :: Ndir
CHARACTER(Ndir) :: dirIn
Print *,"Input Success! Your input are :"
Print *,Ndir
Print *,dirIn