- 积分
- 0
- 注册时间
- 2004-4-13
- 仿真币
-
- 最后登录
- 1970-1-1
|
fortran代码:
=========================
module test
type testtype
sequence
integer*4 :: c
integer*4 :: d(4)
real*8 :: e
real*8 :: f(3)
end type testtype
type(testtype), dimension(5,5) :: aa
contains
subroutine MUTILARRAY(bb,a1,a2)
!DEC$ ATTRIBUTES DLLEXPORT :: MUTILARRAY
implicit none
integer*4 :: i,j,k,a1,a2,l
real*8, dimension(a1:a2) :: b_te
real*8 :: bb
do i=1,5
do j=1,5
aa(i,j).c=bb
aa(i,j).e=bb*2.5
do k=1,3
aa(i,j).d(k)=bb*3
aa(i,j).f(k)=bb*1.5
end do
end do
end do
forall(l=1:3)
b_te(l)=aa(1,3).f(l)
end forall
end subroutine MUTILARRAY
end module test
=======================================
c#代码
=======================================
public partial class Form1 : Form
{
[StructLayout(LayoutKind.Sequential)]
public struct aaa
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public double[] f;
}
aaa[] ate = new aaa[5];
调用:
[DllImport("testdll.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
public static extern void MUTILARRAY(double dd, aaa[] ate);
============================================
发现由c#调用时,如果结构体含有数组,那么结构体定义数据,如果结构体不含有数组,用结构体定义数组,这样数据套数组或者数组套数据都没有问题。但是如果结构体含有数组,再用结构体定义数组,即数组套数组就会出现传递值出错的情况。请问如何解决这个问题?
[ 本帖最后由 piteqiu 于 2008-10-7 12:50 编辑 ] |
|