#include <stdio.h>
#include <string.h>
extern "C" {void _stdcall vlhm_forecast(char *);}
int main()
{
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);
}
subroutine vlhm_forecast(filename)
!DEC$ ATTRIBUTES STDCALL,DLLEXPORT::vlhm_forecast
character(len=*)::filename !c++主程序中传递进来的“Inputfile”变量
write(*,*)"dll里的filename值是:"
write(*,*)filename
end subroutine
error1.png (22.58 KB, 下载次数: 357)
输出乱码图
subroutine vlhm_forecast(filename,lens)
!DEC$ ATTRIBUTES STDCALL,DLLEXPORT::vlhm_forecast
!DEC$ ATTRIBUTES REFERENCE :: filename
character(len=lens)::filename !c++主程序中传递进来的“Inputfile”变量
integer lens
write(*,*)"dll in filename is:"
write(*,*)filename
end subroutine
extern "C" {void _stdcall 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;
}
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
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;
}
fcode 发表于 2016-11-3 11:32
在这个过程中,你用到了很多不规范的用法。只能在 IVF 编译器上使用。
更规范的用法是,使用 ISO_C_Bindin ...
YWNXN)01VERI5N[189FE1UK.png (25.11 KB, 下载次数: 359)
图一
I)1RUAEEH3GM(3GWEKW4KC1.png (30.05 KB, 下载次数: 329)
图二
849(YD5GD_($LIX0ZMNGWY9.jpg (292.27 KB, 下载次数: 347)
图三
0MX9ZBNQ$~IITFEW{MV[0Z0.jpg (280.94 KB, 下载次数: 349)
图四
fcode 发表于 2016-11-17 09:00
int main(){
就可以了。毕竟你只是测试。
fcode 发表于 2016-11-17 18:51
我的意思是改成
int main()
去掉里面的参数
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |