[C++] syntaxhighlighter_viewsource syntaxhighlighter_copycode
#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <msclr\marshal_cppstd.h>
#include "float.h"
#include <string>
#include <math.h>
#include <cstring>
#include <vector>
#include <istream>
#include <fstream>
using namespace msclr::interop;
using namespace std;
extern "C" {
void __stdcall GETSTRING( char *A,
int LEN);
}
void main()
{
char STR[]="hello";
GETSTRING(STR,strlen(STR));
return;
}
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode
subroutine getstring(a)
!DEC$ IF DEFINED (_DLL)
!DEC$ ATTRIBUTES DLLEXPORT ::GETSTRING
!DEC$ END IF
implicit none
character(len=*)::a
write(*,*)a
return
end subroutine
[C++] syntaxhighlighter_viewsource syntaxhighlighter_copycode
extern "C" {
void GETSTRING(char *A,
int LEN);
}
void main()
{
char STR[] = "hello";
GETSTRING(STR, strlen(STR));
return;
}
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode
subroutine getstring(a,n) Bind( C , Name = "GETSTRING" )
!DEC$ ATTRIBUTES DLLEXPORT ::GETSTRING
use ,Intrinsic::ISO_C_Binding
implicit none
type(C_PTR) , value :: a !c++主程序中传递进来的“a”变量,是C语言的指针
integer , value :: n !传入的字符串长度
character(len=n),pointer::pa !这是Fortran的字符串指针
call c_f_pointer( a , pa ) !把c语言的指针转换成fortran字符串指针
write(*,*) pa
end subroutine