#include "stdafx.h"
#include <stdio.h>
#include <string.h>
extern "C" {void _stdcall main(char *,int); }
int _tmain(int argc, _TCHAR* argv[])
{
char *inputfile= "Passing...Good Luck!";
main(inputfile,strlen(inputfile));
return 0;
}
subroutine main( pfilename , lens )
!DEC$ ATTRIBUTES stdcall,ALIAS:"_main@8",DLLEXPORT::main
use ,Intrinsic::ISO_C_Binding
implicit none
type(C_PTR) , value :: pfilename
integer,value::lens
character(len=lens),pointer::filename_a
character(len=512)::filename_b
character(len=512)::path_one,path_two
call c_f_pointer( pfilename , filename_a )
filename_b=filename_a
write(*,*)"传进来的字符串是:",trim(filename_b)
path_one="Hello World!"
write(*,*)"Path_one是:",trim(path_one)
path_two=path_one
write(*,*)"Path_two是:",trim(path_two)
end subroutine
a.jpg (12.61 KB, 下载次数: 227)
“直接运行”的结果
b.jpg (8.73 KB, 下载次数: 222)
图b
c.jpg (20.64 KB, 下载次数: 221)
d.jpg (26.07 KB, 下载次数: 232)
f.jpg (19.95 KB, 下载次数: 223)
图f
g.jpg (30.28 KB, 下载次数: 212)
h.jpg (53.76 KB, 下载次数: 221)
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
extern "C" {void main(char *,int); }
int _tmain(int argc, _TCHAR* argv[])
{
char *inputfile= "Passing...Good Luck!";
main(inputfile,strlen(inputfile));
return 0;
}
subroutine main( pfilename , lens )Bind(C,Name="main")
!DEC$ ATTRIBUTES DLLEXPORT ::main
use ,Intrinsic::ISO_C_Binding
implicit none
type(C_PTR) , value :: pfilename
integer,value::lens
character(len=lens),pointer::filename_a
character(len=512)::filename_b
character(len=512)::path_one,path_two
call c_f_pointer( pfilename , filename_a )
filename_b=filename_a
write(*,*)"传进来的字符串是:",trim(filename_b)
path_one="Hello World!"
write(*,*)"Path_one是:",trim(path_one)
path_two=path_one
write(*,*)"Path_two是:",trim(path_two)
end subroutine
1.jpg (23.46 KB, 下载次数: 236)
图1
图2.jpg (9.92 KB, 下载次数: 219)
图3.jpg (38.05 KB, 下载次数: 237)
图3
图4.jpg (50.34 KB, 下载次数: 231)
pasuka 发表于 2016-12-12 13:15
请先搞明白main函数在C和C++中的地位
Main function - cppreference.com
http://en.cppreference.com/w/cpp ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |