I am having trouble creating a structure that I can send to a Delphi 5 DLL. The DLL is expecting a structure containing 9 bytes containing 1 Byte and 2 Int32's.
If I create a structure with just the one byte field, the Marshal.SizeOf() equals 1.
If I create a structure with the two Int32 fields, the Marshal.SizeOf() equals 8.
However, if I create the structure with all three fields, the Marshal.SizeOf() equals 12. This does not add up, it should be equal to 9.
I have tried using a structure attribute of <StructLayout(layoutkind.Sequential)> and it did not help.
I tried using a structure attribute of <StructLayout(layoutkind.Explicit)> with <FieldOffset
> attributes on the fields and it did not help.
I really need the structure to be 9 bytes. I hope someone has run into this and can help.
Here's the Code:
Pat B
If I create a structure with just the one byte field, the Marshal.SizeOf() equals 1.
If I create a structure with the two Int32 fields, the Marshal.SizeOf() equals 8.
However, if I create the structure with all three fields, the Marshal.SizeOf() equals 12. This does not add up, it should be equal to 9.
I have tried using a structure attribute of <StructLayout(layoutkind.Sequential)> and it did not help.
I tried using a structure attribute of <StructLayout(layoutkind.Explicit)> with <FieldOffset
I really need the structure to be 9 bytes. I hope someone has run into this and can help.
Here's the Code:
Code:
Private Sub btn1_Click(ByVal sAs System.Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim myTest1 as TTest1
Dim myTest2 as TTest2
Dim iSize1, iSize2 as Int32
iSize1 = Marshal.SizeOf(myTest1)
iSize2 = Marshal.SizeOf(myTest2)
End Sub
Public Structure TTest1 ' Size
Public ActiveMessage As Int32 'PChar 004
Public ActiveMessageSize As Int32 'Integer 004
End Structure
Public Structure TTest2 ' Size
Public Active As Byte 'Boolean 001
Public ActiveMessage As Int32 'PChar 004
Public ActiveMessageSize As Int32 'Integer 004
End Structure
Pat B