gudguy

here's the C++ code

Code Block

public struct xvid_dec_stats_t
{
int version;

int type; /* [out] output data type */
union {
struct { /* type>0 {XVID_TYPE_IVOP,XVID_TYPE_PVOP,XVID_TYPE_BVOP,XVID_TYPE_SVOP} */
int general; /* [out] flags */
int time_base; /* [out] time base */
int time_increment; /* [out] time increment */

/* XXX: external deblocking stuff */
int * qscale; /* [out] pointer to quantizer table */
int qscale_stride; /* [out] quantizer scale stride */

} vop;
struct { /* XVID_TYPE_VOL */
int general; /* [out] flags */
int width; /* [out] width */
int height; /* [out] height */
int par; /* [out] pixel aspect ratio (refer to XVID_PAR_xxx above) */
int par_width; /* [out] aspect ratio width [1..255] */
int par_height; /* [out] aspect ratio height [1..255] */
} vol;
} data;
}


Anyone pls help me create the C# signature for the C++ struct above. This is the first time i saw a struct within a struct, then using "union". Its pretty complicated for me.

Many thanks!!

regards,
gudguy



Re: Visual C# General C# equivalent for this complicated C++ struct

Mattias Sjogren

Try it like this

Code Block

struct vop_struct
{
public int general;
public int time_base;
public int time_increment;
public IntPtr qscale;
public int qscale_stride;
}

struct vol_struct
{
public int general;
public int width;
public int height;
public int par;
public int par_width;
public int par_height;
}

[StructLayout(LayoutKind.Explicit)]
struct xvid_dec_stats_t
{
[FieldOffset(0)] public int version;
[FieldOffset(4)] public int type;
[FieldOffset(8)] public vop_struct vop;
[FieldOffset(8)] public vol_struct vol;
}






Re: Visual C# General C# equivalent for this complicated C++ struct

gudguy

Thank you Mattias... i will try this code.

regards,
gudguy