发送
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type aaa
intID As Integer
strName As String
End Type
Dim a As aaa
Dim b As aaa
Dim bt3() As Byte
a.intID = 10
a.strName = "sdfasdfasdf"
ReDim bt3(LenB(a))
CopyMemory bt3(0), a, LenB(a)
'这样就可以senddate bt3
-----------------------------接受
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type aaa
intID As Integer
strName As String
End Type
Dim b As aaa
CopyMemory b, bt3(0), LenB(a)
MsgBox b.intID
---------------------我的单机测试代码
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type aaa
intID As Integer
strName As String
End Type
Private Sub Command2_Click()
Dim a As aaa
Dim b As aaa
Dim bt3() As Byte
a.intID = 10
a.strName = "sdfasdfasdf"
ReDim bt3(LenB(a))
CopyMemory bt3(0), a, LenB(a)
CopyMemory b, bt3(0), LenB(a)
MsgBox b.intID
End Sub