Interop: union in a struct

M

Markus Stiller

Hello I have struct and there is a union in. (C DLL). Could someone
give me ideas how to do it? I just tried for a while but without
success...

thats the c code:
typedef struct {
unsigned int busType;
union {
struct {
unsigned int bitRate;
unsigned char sjw;
unsigned char tseg1;
unsigned char tseg2;
unsigned char sam; // 1 or 3
unsigned char outputMode;
}can;
unsigned char raw[32];
}data;
} XLbusParams;

thats my definition in VB.net

<StructLayout(LayoutKind.Sequential)> _
Structure s_xl_busParams
Public busType As UInt32
Public data As s_xl_UnionBusParams
End Structure

<StructLayout(LayoutKind.Explicit)> _
Structure s_xl_UnionBusParams
<FieldOffset(0)> Public can As s_xl_can
<FieldOffset(0)> <MarshalAs(UnmanagedType.ByValArray,
SizeConst:=32)> _
Public reserved() As UInt32
End Structure

but have a problem using the last field offset command. i tried it
also with
<FieldOffset(0)> raw() as byte

but havent success. in doc is an example with overload at declaration
but dont have an idea how to do it in a struct.
 
R

Roy Soltoff

Check out the structs tutorial section, "Attributes on Structs". Using that
technique, you can create a union.
 

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

Top