当前位置:编程学习 > C#/ASP.NET >>

c#与fortran混合编程,不能同时传递和数组和打开文件

使用C#调用FORTRAN生成的DLL,出现了程序自动死的现象,而如果不在fortran程序中打开文件或者不传递数组,就可以正常运行,fortran程序如下: 
FUNCTION SORTANDFINDMAX(ARRAY,LENGTH,path)
!MS$ ATTRIBUTES DLLEXPORT::SORTANDFINDMAX
!MS$ ATTRIBUTES  ALIAS:'Sortandfindmax'::SORTANDFINDMAX
INTEGER::I,J,LENGTH
REAL(4) ::ARRAY(LENGTH)
    real*4  ::SORTANDFINDMAX
character(len=*) :: path 
      REAL(4)                    :: Dum_Real
      i= readwind(path)

      end     
FUNCTION readwind(path)
real*4  ::readwind
character(len=*) :: path 
      REAL(4)                    :: Dum_Real
      open(11,file=path,form='unformatted',status='old',share='denynone',
recl=4,ACCESS='DIRECT')      
      READ (11,rec=8)  Dum_Real
  readwind  = Dum_Real
      close(11,status='delete')  
   end
C#程序如下:
public static class FortranMethod
        {
            [DllImport(@"C:\MSDEV\Projects\222222\Debug\222222.dll", CallingConvention = CallingConvention.StdCall)]
         public static extern float Sortandfindmax(float[] array, int length, string path);
        }


        private void button20_Click(object sender, EventArgs e)
        {
          string path = "C:\\MSDEV\\Projects\\readwnd\\wind778.wnd";
         float[] Array =new float[7] ;
         try
            {
                float b = FortranMethod.Sortandfindmax(Array, Array.Length, path);
            }
            catch (Exception)
            {
                
                throw;
            }
} c#与fortran混合编程 fortran c# 不能同时传递和数组和打开文件
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,