C结构体里包含有结构指针成员,这样的结构如何转换为C#的结构体typedef struct{
    int a;
    int b;
}StructA, *LPStructA
typedef struct{
    int a;
    LPStructA structA;
}StructB
第二个结构体如何转为C#的形式

解决方案 »

  1.   

    用IntPtr代替,或者直接将StructA声明为class,这样就等效于指针访问了,存储的是地址。
      

  2.   

    因为我是接收对方SDK接口传过来的东西,对方用的是结构体,我用C#的接也必须用结构体,所以只好用你说的IntPtr,就是说要转成
    public struct StructB
    {
      public int a;
      public IntPtr structA;
    }
    但是我在使用回传的StructB数据时,怎么知道IntPtr structA就是LPStructA structA,使用
    强制转换(StructA)structA吗
      

  3.   

    typedef struct{
      int a;
      int b;
    }StructA, *LPStructA
    这个也定义一遍,然后
    StructA sa = (StructA)Marshal.PtrToStructure(StructB.structA, typeof(StructA));
      

  4.   

    public struct StructA
    {
        public int a;
        public int b;
    };
    public struct StructB : IDisposable
    {
        public int a;
        public IntPtr structA;    public void Dispose()
        {
            System.Runtime.InteropServices.Marshal.FreeHGlobal(structA);
        }
        public StructA StructA
        {
            get
            {
                return (StructA)System.Runtime.InteropServices.Marshal.PtrToStructure(structA, typeof(StructA));
            }
        }
    }