Public Type uS a As Long b As Double c As String * 48End Type
Public Data1() As uSPublic outArray() as byte
如果将 data1转换成 byte数组呢?还有如何恢复byte数组到 data1中呢?——————————————————————————
用CopyMemory来做.
例子:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Type uS a As Long b As Double c As String * 48End Type
Private Sub Command1_Click()Dim Data1 As uSDim outArray() As Byte
Data1.a = 5Data1.b = 8Data1.c = "aa"
ReDim outArray(Len(Data1))CopyMemory outArray(0), Data1, Len(Data1) '将结构的信息传入字节数组中.
MsgBox UBound(outArray)MsgBox outArray(0)
Dim abc As uSCopyMemory abc, outArray(0), UBound(outArray) '将字节数组还原到结构中
MsgBox abc.cEnd Sub