Option Explicit Private Type InputStructure monLong1 As Long ' 4 octets/bytes monByte1 As Byte ' 1 octets/bytes monLong2 As Long ' 4 octets/bytes End Type Private oInputDatas As InputStructure Private aOutputBytes() As Byte Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" ( _ pDst As Any, _ pSrc As Any, _ ByVal ByteLen As Long)
With oInputDatas .monLong1 = &H499602D2 ' 1234567890 en décimal .monByte1 = &H6F ' 111 en décimal .monLong2 = &H42E576F7 ' 1122334455 en décimal End With ' Prépare un tableau de même longueur (qui commence à l'index 0) ReDim aOutputBytes(LenB(oInputDatas) - 1) ' Transfert des données Call CopyMemory(aOutputBytes(0), _ ByVal VarPtr(oInputDatas), _ LenB(oInputDatas))
If UBound(aOutputBytes) <= 0 Then Exit Sub Dim oRecup As InputStructure ' Transfert des données Call CopyMemory(oRecup, _ ByVal VarPtr(aOutputBytes(0)), _ UBound(aOutputBytes) + 1) ' Vérif With oRecup Debug.Print "Premier Long", .monLong1 Debug.Print "Premier Byte", .monByte1 Debug.Print "Second Long", .monLong2 End With
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic ty_6002 Pad As Byte DataChkS As Long End Type Public M6002 As ty_6002 Private aOutputBytes() As Byte Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" ( _ pDst As Any, _ pSrc As Any, _ ByVal ByteLen As Long) Private Sub Sendm6002() M6002.Pad = &HAA M6002.DataChkS = &HF0F0F0F0 ReDim aOutputBytes(LenB(M6002) - 1) Call CopyMemory(aOutputBytes(0), ByVal VarPtr(M6002), LenB(M6002)) For i = 0 To UBound(aOutputBytes) Mytxt = Mytxt + "Byte(" + CStr(i + 1) + ")" + _ vbTab + Hex(SendMessge(i)) + vbCrLf Next i WS.SendData aOutputBytes End Sub