UNION with nested Structs

  • Thread starter Thread starter Sean S.
  • Start date Start date
S

Sean S.

I have been following the strings of Unions here however I have not yet
seen any that can help me with this one... I am needing to convert some
16bit C code into C#... can some one assist? Here is a bit of the code:

typedef union
{
struct
{
int nZWord;
int nFId;
};

struct
{
int nFieldId;
int nIndex;
};

} MARKER;


Any assistance is appreciated... Thanks!

SFS
 
Sean,

You could do this in the following manner:

[StructLayout(LayoutKind.Explicit)]
public struct MARKER
{
[FieldOffset(0)]
public int nZWord;
[FieldOffset(4)]
public int nFId;
[FieldOffset(0)]
public int nFieldId;
[FieldOffset(4)]
public int nIndex;
}

For more information on how to marshal structures with unions (or unions
in general), check out the section of the .NET framework documentation
titled "Unions Sample".

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top