There are other CopyMemory fans out there!
For some unknown super-weird reason, putting a Long in a UDT messes up a Byte in the same UDT.
So, don't use regular Longs! :rolleyes:
Put this in the form:
Code:
Option Explicit
Private Type YonaLong
btLoByte As Byte
btByte2 As Byte
btByte3 As Byte
btHiByte As Byte
End Type
Private Type typeInMsg
Size As YonaLong
Function As Byte
TID As YonaLong
Seq As YonaLong
Msg(255) As Byte
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal cbSrc As Long)
Private Property Get YonaLongThing(dwLong As Long) As YonaLong
Call CopyMemory(YonaLongThing, dwLong, 4)
End Property
Private Property Let YonaLongThing(dwLong As Long, tYonaLong As YonaLong)
Call CopyMemory(dwLong, tYonaLong, 4)
End Property
Here's how you can use it:
Code:
' Long->YonaLong
' Instead of:
InMsg.TID = 20562
' Use this:
InMsg.TID = YonaLongThing(20562)
' YonaLong->Long
' Instead of:
SomeVariable = InMsg.TID
' Use this:
YonaLongThing(SomeVariable) = InMsg.TID
YonaLong does not mess up any Bytes... Because it's made of Bytes itself.
So, using CopyMemory to convert the UDT to a Byte array, or using it to convert the Byte array to a UDT, should work with no problems now. :rolleyes:
Thanks Kedaman and Yonatan
Thanks guys, great tips.
As I have no control over the Server, and the byte stream has to be as per my original post, then I guess it's time to switch to YonaLong!
I just wanted to make sure that I wasn't going nuts.
Cheers
Adrian.