I defined a structure with a long variable, which is located on an even boundary, but the compiler handles this as if the long is located on a 4-byte boundary. The strange thing is that the compiler shows the correct total length of the structure (as if there are no slack bytes).
You can see this for yourself.
Create an agent and populate it with the following code:
Type Wrong
ifield1 As Integer
lfield As Long
ifield2 As Integer
End Type
Declare Private Sub Poke Lib “MSVCRT” Alias “memcpy” ( Byval P As Long, D As Any, Byval N As Long)
Declare Function W32_OSLockObject Lib “nnotes.dll” Alias “OSLockObject” (Byval handle As Long) As Long
Declare Function W32_OSUnlockObject Lib “nnotes.dll” Alias “OSUnlockObject” (Byval handle As Long) As Integer
Declare Function W32_OSMemAlloc Lib “nnotes.dll” Alias “OSMemAlloc” ( Byval x As Integer, Byval y As Long, z As Long) As Integer
Declare Sub MoveMemory Lib “kernel32” Alias “RtlMoveMemory” (Destination As Any, Source As Any, Byval Length As Long)
Sub Initialize
Dim w As Wrong
Dim rc As Integer
Dim p As Long
Dim pw As Long
w.ifield1 = 255
w.lfield = 1
w.ifield2 = 16
Msgbox "Size of Wrong: " + Cstr(Len(w))
rc = W32_OSMemAlloc(0, Len(w), pw)
p = W32_OSLockObject(pw)
Call Poke(p, w, Len(w))
Call dumpHandle(pw, Len(w))
W32_OSUnlockObject(pw)
End Sub
Sub dumpHandle(hbuffer As Long, hlen As Long)
Dim i As Long
Dim pbuffer As Long
Dim dump As String
pbuffer = W32_OSLockObject(hbuffer)
Redim buffer(1 To hlen) As Byte
MoveMemory buffer(1), Byval pbuffer, hlen
For i = 1 To hlen
dump = dump + " " + Right$("0" + Hex(buffer(i)), 2)
Next
dump = Left$(dump, hlen * 3)
W32_OSUnlockObject(hbuffer)
Msgbox dump
End Sub
When you run this, you will notice that the size of the structure is 8 bytes, which is correct.
Its value should be FF FF 01 00 00 00 10 00, but it is:
FF 00 00 00 01 00 00 00
It shows two things:
a) the first byte is filled, but the first 2 bytes should contain FF FF.
b) there are 2 extra 00 included.
Who recognises this?