/*结构体原型
typedef struct { 
unsigned int s;
unsigned int d; 
unsigned int SP[4][4];
} A;typedef struct { 
unsigned char mv;  
unsigned char n;  
B sb;  
unsigned int cn;  
unsigned int Seg[8];  
int* r1; 
unsigned char* r2[512]; 
} B; */
用C#怎么写

解决方案 »

  1.   

    指针的还不知道怎么表示,但是类型嵌套应是如下的样式:struct b
    {
    public char mv;
    public char n;
    public b sp;
    public int cn;
    public int[] Seg=new int[8];
    ...
    }
      

  2.   

    struct不是很好写,要用到Invoke的那种写法
    简单的方法就是把struct当成class来写
      

  3.   

    public int[] Seg=new int[8];
    struct中不能有new 不能赋值
      

  4.   

    public int[8] Seg;
    一样报错  不能这么写
    要用到那个[Mar..]什么的忘了
      

  5.   

    [Marshal]
    我是建议把struct当成class来写 反正是一样的调用
    指针麻..........,Marshal里好像也有
      

  6.   

    嵌套不能用public b sp;
    错误信息:causes a cycle in the struct layout
      

  7.   

    '这里有VB.NET的写法,可以用C#写出来吗    Public Const C1 As Short = 8
        Public Const C2 As Short = 8    Structure A
            Dim s As Integer 
            Dim d As Integer 
            <VBFixedArray(C1, 4)> Dim Sig(,) As Integer
            
            Public Sub Initialize()
                ReDim Sig(C1, 4)
            End Sub
        End Structure     Structure B
            <VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=1)> Public mv As String
            <VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=1)> Public n As String       
            Dim sb As B
            Dim cn As Integer
            <VBFixedArray(C2)> Dim Seg() As Integer        Public Sub Initialize()
                ReDim Seg(C2)
            End Sub
        End Structure