DOUBLE PRECISION FUNCTION ADD(A,B)
!DEC$ ATTRIBUTES DLLEXPORT::ADD
!DEC$ ATTRIBUTES STDCALL,ALIAS:'Add'::ADD
DOUBLE PRECISION:: A,B
ADD=A+B
END
FUNCTION SORTANDFINDMAX(ARRAY,LENGTH)
!DEC$ ATTRIBUTES DLLEXPORT::SORTANDFINDMAX
!DEC$ ATTRIBUTES STDCALL,ALIAS:'Sortandfindmax'::SORTANDFINDMAX
DOUBLE PRECISION ::ARRAY(LENGTH)
INTEGER::I,J
DOUBLE PRECISION::SORTANDFINDMAX,TEMP
SORTANDFINDMAX=ARRAY(1)
DO I=1,LENGTH-1
DO J=I+1,LENGTH
IF(ARRAY(I).GT.ARRAY(J)) THEN
TEMP=ARRAY(I)
ARRAY(I)=ARRAY(J)
ARRAY(J)=TEMP
SORTANDFINDMAX=ARRAY(J)
END IF
END DO
END DO
END
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace MixedProgram
{
public static class FortranMethod
{
[DllImport("TestDll.dll" ,CallingConvention = CallingConvention.Cdecl)]
public static extern double Add(double a, double b);
[DllImport("TestDll.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double Sortandfindmax(double[] arry, int length);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MixedProgram
{
class Program
{
static void Main(string[] args)
{
//测试第一个方法
Console.WriteLine("请输入两个数相加");
double num1 = Convert.ToDouble(Console.ReadLine());
double num2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("输入的两个数是:" + num1 + "," + num2);
double sum = FortranMethod.Add(num1, num2);
Console.WriteLine("求和结果是:" + sum);
//测试第二个方法
double[] Array = { 1, 5, 2, 4, 3, 7, 6 };
Console.WriteLine("初始数组:");
for (int i = 0; i < Array.Length; i++)
{
Console.Write(Array + "");
}
double b = FortranMethod.Sortandfindmax(Array, Array.Length);
Console.Write("\n" + "排序后:");
for (int i = 0; i < Array.Length; i++)
{
Console.Write(Array + "");
}
Console.WriteLine("\n" + "最大值为:");
Console.WriteLine(b);
Console.ReadKey();
}
}
1609246065(1).jpg (21.52 KB, 下载次数: 270)
Real(kind=8) FUNCTION Add(A,B) Bind(C,Name="Add")
!DEC$ ATTRIBUTES DLLEXPORT::Add
Real(8) , value :: A,B
ADD=A+B
END Function Add
fcode 发表于 2020-12-30 08:32
DOUBLE PRECISION FUNCTION ADD(A,B)
!DEC$ ATTRIBUTES DLLEXPORT::ADD
!DEC$ ATTRIBUTES STDCALL,ALIAS:'A ...
T0)M3~M(0()93%[]1NB{5`8.png (39.62 KB, 下载次数: 275)
Chastar 发表于 2020-12-30 09:37
感谢解答但改了过后还是不行,出现同样的错误,我看网上说是要将VS跟啥Intel Parallel Studio XE 2019绑 ...
HNHJJ)XK_5@])GL`LDX%LFX.png (175.54 KB, 下载次数: 291)
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |