前面已经讲过如何在vb6中实现将多个字节还原成其实际的原始类型,那么我们也经常需要在上位机上将浮点数等数据按照字节进行传输。
废话不多说了,直接给出系列源码,请参考之前的文章来看吧。
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any,Source As Any,ByVal Length As Long)
Private Declare Function VarPtr Lib "MSVBVM60.DLL" (var As Any) As Long
Private Sub Command1_Click()
Dim f As Single
Dim b(4) As Byte
f = 3.14
CopyMemory ByVal VarPtr(b(0)),ByVal VarPtr(f),1
CopyMemory ByVal VarPtr(b(1)),ByVal VarPtr(f) + 1,1
CopyMemory ByVal VarPtr(b(2)),ByVal VarPtr(f) + 2,1
CopyMemory ByVal VarPtr(b(3)),ByVal VarPtr(f) + 3,1
MsgBox "0x" & Hex(b(0)) & "," & "0x" & Hex(b(1)) & "," & "0x" & Hex(b(2)) & "," & "0x" & Hex(b(3))
End Sub