2

私は、c#からCdllに渡される別の構造内に単純な構造を埋め込む方法を理解しようとしています。埋め込まれた構造をどのようにマーシャリングしますか?必需品まで取り除いた。

//The C code
typedef struct {
       int a;
       int b;
} A;
typedef struct {
      int c;
      A myStruct;
} B;

//The c# code:
using System.Runtime.InteropServices;

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public class A{
        int a;
        int b;
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public class B{
          int c;
          public IntPtr A;
     }
4

1 に答える 1

0
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class B{
      int c;
      public A a;
    }

Bが次のように定義されている場合にのみIntPtrが必要です。

typedef struct {
      int c;
      A* myStruct;
} B;
于 2012-08-14T14:45:53.123 に答える