主题:高手帮帮忙吧!
Fortran Dll 代码:
module test
type testtype
integer c
real*8 e
integer,pointer:: d(:)
end type testtype
end module test
subroutine MUTILARRAY(bb)
!DEC$ ATTRIBUTES DLLEXPORT :: MUTILARRAY
use test
type(testtype) bb
write(*,*) bb.c !C#传给的值
bb.c=1
write(*,*) bb.c !改变后的值
write(*,*) bb.e !C#传给的值
bb.e=2
write(*,*) bb.e !改变后的值
write(*,*) bb.d(1) !C#传给的值
bb.d(1)=5
write(*,*) bb.d(1) !改变后的值
end subroutine MUTILARRAY
C#代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace testDll
{
class Program
{
[StructLayout(LayoutKind.Sequential)]
public struct test //参数结构定义
{
public int c;
public double e;
public int[] d;
}
//外部引用DLL说明
[DllImport("forDll.dll",CallingConvention =CallingConvention.StdCall , EntryPoint = "MUTILARRAY")]
//DLL接口函数说明
static extern void MUTILARRAY(ref test aa);
static void Main(string[] args)
{
test aa;
aa.c = 10;
aa.e = 20;
aa.d = new int[4];
for (int i = 0; i < 4; i++)
{
aa.d[i] = i + 1;
}
MUTILARRAY(ref aa);
}
}
}
C#调用怎么老是不通过呢?
是C#调用的问题,还是Fortran定义的问题?
有研究过这方面的大侠请帮帮忙,给指点一下迷津,非常感谢!![em21]
module test
type testtype
integer c
real*8 e
integer,pointer:: d(:)
end type testtype
end module test
subroutine MUTILARRAY(bb)
!DEC$ ATTRIBUTES DLLEXPORT :: MUTILARRAY
use test
type(testtype) bb
write(*,*) bb.c !C#传给的值
bb.c=1
write(*,*) bb.c !改变后的值
write(*,*) bb.e !C#传给的值
bb.e=2
write(*,*) bb.e !改变后的值
write(*,*) bb.d(1) !C#传给的值
bb.d(1)=5
write(*,*) bb.d(1) !改变后的值
end subroutine MUTILARRAY
C#代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace testDll
{
class Program
{
[StructLayout(LayoutKind.Sequential)]
public struct test //参数结构定义
{
public int c;
public double e;
public int[] d;
}
//外部引用DLL说明
[DllImport("forDll.dll",CallingConvention =CallingConvention.StdCall , EntryPoint = "MUTILARRAY")]
//DLL接口函数说明
static extern void MUTILARRAY(ref test aa);
static void Main(string[] args)
{
test aa;
aa.c = 10;
aa.e = 20;
aa.d = new int[4];
for (int i = 0; i < 4; i++)
{
aa.d[i] = i + 1;
}
MUTILARRAY(ref aa);
}
}
}
C#调用怎么老是不通过呢?
是C#调用的问题,还是Fortran定义的问题?
有研究过这方面的大侠请帮帮忙,给指点一下迷津,非常感谢!![em21]