在这个过程中,你用到了很多不规范的用法。只能在 IVF 编译器上使用。 
 
更规范的用法是,使用 ISO_C_Binding。它与上面的区别是,使用了 C 的调用协定(而不是 stdcall) 
 
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode subroutine vlhm_forecast( pfilename , lens ) Bind(C,Name="vlhm_forecast")
!DEC$ ATTRIBUTES DLLEXPORT :: vlhm_forecast
  use , Intrinsic :: ISO_C_Binding
  type(C_PTR) , value :: pfilename !c++主程序中传递进来的“Inputfile”变量,是C语言的指针
  integer , value :: lens  
  character(len=lens) , pointer :: filename     !这是fortran的字符串       
  call c_f_pointer( pfilename , filename ) !//把 c 语言的指针转换成fortran字符串
  write(*,*)"dll in filename is:"
  write(*,*)filename
end subroutine  
[C++] syntaxhighlighter_viewsource syntaxhighlighter_copycode extern "C" {void vlhm_forecast(char *,int); }
int _tmain(int argc, _TCHAR* argv[])
{
  char *inputfile = "C:\\Users\\www\\Desktop\\model_2\\cpp_main\\31005700.tem";
  printf("before calling:\n");
  printf("filename=\"%s\"", inputfile);
  printf("\n");
  vlhm_forecast(inputfile,strlen(inputfile));
  return 0;
} 
这样做的好处是,fortran代码可以不做任何修改的在 linux gcc (或其他平台)上编译。 
 
 
 |