Article ID: 152058
Article Last Modified on 3/18/2005
Byte vbByte Integer vbInteger Long vbLong Single vbSingle Double vbDouble Currency vbCurrency Date vbDate Boolean vbBoolean SCODE vbError String vbString Byte Array vbArray + vbByteBecause user-defined types are not directly supported, you must make use of the byte-array data type in order to pass a user-defined type with the Winsock control. This article demonstrates how to send and receive data contained in a user-defined type with the Winsock Control.
152057 HOWTO: Create & Use a Client/Server Using Winsock TCP Controls
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (_
hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Type MyType
i As Integer
l As Long
s As String * 8
d As Double
End Type
Private Sub TCP1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim vta
Dim mt As MyType
Dim bt() As Byte
TCP1(Index).GetData vta, vbArray + vbByte, LenB(mt)
bt = vta
CopyMemory mt, bt(0), LenB(mt)
Debug.Print mt.i; ","; mt.l; ","; mt.s; ","; mt.d
End Sub
Private Sub cmdSendData_Click()
Dim mt As MyType
mt.i = 99
mt.l = 33
mt.s = "abcd"
mt.d = 23.76
Dim bt() As Byte
ReDim bt(LenB(mt)) as Byte
Dim vtdata As Variant
CopyMemory bt(0), mt, LenB(mt)
vtdata = bt
TCP1.SendData vtdata
End Sub
Keywords: kbwinsock kbapi kbnetwork KB152058