我有一个复杂的结构,我想编组它在C#中使用它。 我得到了#34; FILE" struct用作示例
#pragma pack(4)
typedef struct __file__{
short token; /* Used for validity checking */
unsigned short flags; /* File status flags */
unsigned char hold; /* Ungetc char if no buffer */
int fd; /* File descriptor */
int level; /* fill/empty level of buffer */
int bsize; /* Buffer size */
unsigned char *buffer; /* Data transfer buffer */
unsigned char *curp; /* Current active pointer */
struct __file2{
char *name; /* filename */
enum {
__or_unspecified,
__or_narrow,
__or_wide
} orient; /* stream orientation */
int mbstate[2]; /* space for mbstate_t structure */
} *extended;
} FILE; /* This is the FILE object */
#pragma pack()
那么,我如何将这个结构转换为C#?
我的实际转换是:
[StructLayout(LayoutKind.Sequential, Pack = 4)]
struct FILE
{
public short token;
public ushort flags;
public byte hold;
public int fd;
public int level;
public int bsize;
public UIntPtr buffer;
public UIntPtr curp;
[StructLayout(LayoutKind.Sequential)]
public struct extended
{
public char[] name;
public enum orient
{
__or_unspecified,
__or_narrow,
__or_wide
}
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] mbstate;
}
}
在C结构中,struct __file2是一个指针," * extended;",如何转换它?