主题:『请教』C#调用Fortran编译的DLL
C#调用Fortran编译的DLL,DLL接口函数中含有type类型,并且该类型里面包含二维数组。
fortran接口函数如下:
module programPar
type testType
integer m
integer n
real(8),allocatable:: testData(:,:)
end type
end module
subroutine fdll(X,Y)
!DEC$ ATTRIBUTES DLLEXPORT:: fdll
use programPar
type(testType) X,Y
Y=X
end
该接口函数实现把X结构赋给Y结构并,希望在C#中得到Y结构
在C#下调用如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace test
{
class Program
{
public struct testStruct
{
public int m;
public int n;
public double[,] testData;
}
[DllImport("testdll.dll")]
public static extern void FDLL(ref testStruct X, ref testStruct Y);
static void Main(string[] args)
{
testStruct X=new testStruct();
testStruct Y = new testStruct();
int m = 3;
int n = 2;
X.m = m;
X.n = n;
X.testData = new double[m, n];
Y.testData = new double[m, n];
int i, j, k;
k = 1;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
X.testData [i, j] = (double)k++ / 10;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
Console.WriteLine(Y.testData [i, j]);
Console.WriteLine("-----------------------");
FDLL(ref X, ref Y);
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
Console.WriteLine(Y.testData [i, j]);
Console.Read();
}
}
}
出现如下错误:
见附件图片
希望大侠们帮忙指教一下,非常感谢!
fortran接口函数如下:
module programPar
type testType
integer m
integer n
real(8),allocatable:: testData(:,:)
end type
end module
subroutine fdll(X,Y)
!DEC$ ATTRIBUTES DLLEXPORT:: fdll
use programPar
type(testType) X,Y
Y=X
end
该接口函数实现把X结构赋给Y结构并,希望在C#中得到Y结构
在C#下调用如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace test
{
class Program
{
public struct testStruct
{
public int m;
public int n;
public double[,] testData;
}
[DllImport("testdll.dll")]
public static extern void FDLL(ref testStruct X, ref testStruct Y);
static void Main(string[] args)
{
testStruct X=new testStruct();
testStruct Y = new testStruct();
int m = 3;
int n = 2;
X.m = m;
X.n = n;
X.testData = new double[m, n];
Y.testData = new double[m, n];
int i, j, k;
k = 1;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
X.testData [i, j] = (double)k++ / 10;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
Console.WriteLine(Y.testData [i, j]);
Console.WriteLine("-----------------------");
FDLL(ref X, ref Y);
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
Console.WriteLine(Y.testData [i, j]);
Console.Read();
}
}
}
出现如下错误:
见附件图片
希望大侠们帮忙指教一下,非常感谢!