Hello there everyone.
I just would like to point out something to you.
If you have ever tried receiving packets from an application on a SUN Server, you might have had a little surprise.
Let me give you an example. Lets say you are receiving a header packet that contains the size of some data or something like that.
Whell, you'll realise that using UDTs with Integers or other numeric types will have a strange outcome when a CopyMemory is being issued from the Winsock buffer to your UDT... Numbers are incoherent...
Dont pull you hairs off your head... It is quite normal.
What you are actually getting is a REVERSED expression of your number.... I mean your BYTES have to be read the other way around.
Heres a piece of code that does it.
I hope it may help one of you one day... You might even find out why... cuz I still dont get it.Code:Function ReverseLong(N As Long) As Long Dim forward(4) As Byte Dim backward(4) As Byte Dim counter As Integer Dim Result As Long 'Copy into byte array' CopyMemory forward(0), N, 4 'Swap bytes' For counter = 0 To 3 backward(counter) = forward(3 - counter) Next 'Return the byte reversed number' CopyMemory Result, backward(0), 4 ReverseLong = Result End Function Function ReverseInt(N As Integer) As Integer Dim forward(2) As Byte Dim backward(2) As Byte Dim counter As Integer Dim Result As Integer CopyMemory forward(0), N, 2 For counter = 0 To 1 backward(counter) = forward(1 - counter) Next CopyMemory Result, backward(0), 2 ReverseInt = Result End Function
Greetings to you all.




Reply With Quote