J
Joel
Does anybody know how to get unions to work in VB.Net?
What I'm trying to do is have a structure of a variety of
types of fields, and then I need to pass the whole thing
as a string later on. So I tried (see below) to use
LayoutKind.Explicit with FieldOffset, where I first set
the offset 0 to a string and then laid down the rest of
my fields. But instead of working like a union, it lays
the fields down sequentially (they don't overlap each
other as expected). Anybody know how to do this?
Thanks,
Joel
<System.Runtime.InteropServices.StructLayout
(System.Runtime.InteropServices.LayoutKind.Explicit)>
Public Structure IPCInitReqUnion
<System.Runtime.InteropServices.FieldOffset(0)
(88)> Dim USERID As String
<System.Runtime.InteropServices.FieldOffset
(120)> Dim PASSWORD As String
<System.Runtime.InteropServices.FieldOffset
(152)> Dim LocalLogon As Short
<System.Runtime.InteropServices.FieldOffset
(154)> Dim FTPProcessName() As String
<System.Runtime.InteropServices.FieldOffset
(184)> Dim NodeCount As Short
End Structure
What I'm trying to do is have a structure of a variety of
types of fields, and then I need to pass the whole thing
as a string later on. So I tried (see below) to use
LayoutKind.Explicit with FieldOffset, where I first set
the offset 0 to a string and then laid down the rest of
my fields. But instead of working like a union, it lays
the fields down sequentially (they don't overlap each
other as expected). Anybody know how to do this?
Thanks,
Joel
<System.Runtime.InteropServices.StructLayout
(System.Runtime.InteropServices.LayoutKind.Explicit)>
Public Structure IPCInitReqUnion
<System.Runtime.InteropServices.FieldOffset(0)
<System.Runtime.InteropServices.FieldOffsetDim s As String <System.Runtime.InteropServices.FieldOffset(0)
Dim HEADER As MyHeaderClass
(88)> Dim USERID As String
<System.Runtime.InteropServices.FieldOffset
(120)> Dim PASSWORD As String
<System.Runtime.InteropServices.FieldOffset
(152)> Dim LocalLogon As Short
<System.Runtime.InteropServices.FieldOffset
(154)> Dim FTPProcessName() As String
<System.Runtime.InteropServices.FieldOffset
(184)> Dim NodeCount As Short
End Structure