我试图弄清楚如何将一个简单的结构嵌入到另一个从c#传递给C dll的结构中。你如何编组嵌入式结构?精简到必需品。
//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;
}
答案 0 :(得分:0)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class B{
int c;
public A a;
}
只有在B定义为:
时才需要IntPtrtypedef struct {
int c;
A* myStruct;
} B;