[C++] 纯文本查看 复制代码
#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;
}
[C++] 纯文本查看 复制代码
extern "C" {
void GETSTRING(char *A,
int LEN);
}
void main()
{
char STR[] = "hello";
GETSTRING(STR, strlen(STR));
return;
}
[Fortran] 纯文本查看 复制代码
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