In article <51**********************************@microsoft.co m>, JohnH wrote:
to all
I need to intigrate a vb.net application to a API (written for c) that deals
with processing messages. Each message type is represented by a structure.
All message structures are containded in a union "Message".
In c the code would be as follows:
typedef struct
{
EventHeaderType eventHeader;
union
{
Event1Type event1;
Event2Type event2;
Event3Type event3;
Event3Type event4;
} event;
char heap[MAX_HEAP];
}EventType;
How can this be done in vb.net?
You need to adjust the marshalling attributes of the structure. I can't
give you an exact declaration, because you don't includ ethe
EventHeaderType and evnet type declarations... But, it would look
something like:
<StructLayout (LayoutKind.Explicit)> _
Public Structure UnionType
<FieldOffset (0)> _
Public event1 As Event1Type
<FieldOffset (0)> _
Public event2 As Event2Type
<FieldOffset (0)> _
Public event3 As Event3Type
<FieldOffset (0)> _
Public event4 As Event4Type
End Union
<StructLayout (LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure EventType
Public eventHeader As EventHeaderType
Public union As UnionType
<MarshalAs (UnmanagedType.ByValTStr, SizeConst:=MAX_HEAP)> _
Public heap As String
End Structure
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 0 Days, 3 Hours, 28 Minutes, 36 Seconds