Bug in framework 2.0

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eyal Safran

    #1

    Bug in framework 2.0

    Hello,

    I've tried to create a matching MMTIME struct in C# to pass to the
    timeGetSystemTi me DllImported method... here are my structs:

    [StructLayout(La youtKind.Sequen tial)]
    public struct MMTIME
    {
    public uint wType;
    [MarshalAs(Unman agedType.Struct )]
    public Union u;

    [StructLayout(La youtKind.Explic it)]
    public struct Union
    {
    [FieldOffset(0)] public uint ms;
    [FieldOffset(0)] public uint sample;
    [FieldOffset(0)] public uint cb;
    [FieldOffset(0)] public uint ticks;
    [FieldOffset(0)] [MarshalAs(Unman agedType.Struct )] public
    SMPTE smpte;
    [FieldOffset(0)] [MarshalAs(Unman agedType.Struct )] public
    MIDI midi;
    }

    [StructLayout(La youtKind.Sequen tial)]
    public struct SMPTE
    {
    public byte hour;
    public byte min;
    public byte sec;
    public byte frame;
    public byte fps;
    public byte dummy;
    public ushort pad;
    }

    [StructLayout(La youtKind.Sequen tial)]
    public struct MIDI
    {
    public uint songptrpos;
    }
    }

    When I do:

    Marshal.SizeOf( typeof(MMTIME.M IDI)); = 4
    Marshal.SizeOf( typeof(MMTIME.S MPTE)); = 8
    Marshal.SizeOf( typeof(MMTIME.U nion)); I get:

    Type 'Common.Structu res.MMTIME+Unio n' cannot be marshaled as an
    unmanaged structure; no meaningful size or offset can be computed.

    I tried remarking from the Union struct, any 1 of the 2 structures
    members, and when I remaked the MIDI structure, it passed the
    Marshal.SizeOf.

    on the other hand, if i Add to the MIDI structure another member (so
    that the struct now contains more than 1 memebr) it also works,
    example:

    [StructLayout(La youtKind.Sequen tial)]
    public struct MIDI
    {
    public uint songptrpos;
    public uint tmp;
    }

    my guess is a Marshal.SizeOf does not work on structs which contains
    another struct with 1 member in it...

    Best Regards,

    Eyal Safran.

Working...