Maybe we can say that.
You must take care of the type of the data you have in your structures
(about the length in bytes of each variable).
A sample of a Getbytes/Decode functions (sorry but the comments are in
French) :
'--------------------------------------------------------
'Transforme une instance de ActionKey en tableau de bytes
'
'Valeur retournée :
' TRUE si OK, FALSE sinon
'--------------------------------------------------------
Private Function GetBytes(ByRef TabBytes() As Byte) As Boolean
Dim i As Integer
Dim max As Integer
Dim max2 As Integer
Try
'On redimensionne le tableau
ReDim TabBytes(1324)
'Entier IDBouton = 4 bytes
BitConverter.GetBytes(IDBouton).CopyTo(TabBytes, 0)
'Entier TypeClick = 4 bytes
BitConverter.GetBytes(TypeClick).CopyTo(TabBytes, 4)
'Entier Typeaction = 4 bytes
BitConverter.GetBytes(TypeAction).CopyTo(TabBytes, 8)
'Booléen Son = 4 bytes
BitConverter.GetBytes(Son).CopyTo(TabBytes, 12)
'Tableau de bytes Keyboard = 260 * 1 byte
If Not IsNothing(Keyboard) Then
max = Keyboard.GetUpperBound(0)
For i = 0 To max
TabBytes(i + 16) = Keyboard(i)
Next
End If
'Entier TailleKeyboard = 4 bytes
BitConverter.GetBytes(TailleKeyboard).CopyTo(TabBytes, 276)
'Entier DureeClick = 4 bytes
BitConverter.GetBytes(DureeClick).CopyTo(TabBytes, 280)
'Tableau de caractères Application = 260 * 2 bytes
If Not IsNothing(Application) Then
max = Application.GetUpperBound(0)
For i = 0 To max
BitConverter.GetBytes(Application(i)).CopyTo(TabBytes, 284 + (2 * i))
Next
End If
'Tableau de caractères Paramètres = 260 * 2 bytes
If Not IsNothing(Parametres) Then
max = Parametres.GetUpperBound(0)
For i = 0 To max
BitConverter.GetBytes(Parametres(i)).CopyTo(TabBytes, 804 + (2 * i))
Next
End If
GetBytes = True
Catch ex As Exception
GetBytes = False
End Try
End Function
'---------------------------------------------------------------------------
----------
'Analyse le tableau de bytes retourné par lecture des infos d'un bouton du
Gotive
'et inscrit ces données dans les membres de la classe
'
'Valeur retournée :
' TRUE si OK, FALSE sinon
'---------------------------------------------------------------------------
----------
Private Function Decode(ByVal TabBytes() As Byte) As Boolean
Dim i As Integer
Try
'Entier IDBouton = 4 bytes
IDBouton = BitConverter.ToUInt32(TabBytes, 0)
'Entier TypeClick = 4 bytes
TypeClick = BitConverter.ToUInt32(TabBytes, 4)
'Entier Typeaction = 4 bytes
TypeAction = BitConverter.ToUInt32(TabBytes, 8)
'Booléen Son = 4 bytes
Son = BitConverter.ToBoolean(TabBytes, 12)
'Tableau de bytes Keyboard = 260 * 1 byte
For i = 0 To 259
Keyboard(i) = TabBytes(i + 16)
Next
'Entier TailleKeyboard = 4 bytes
TailleKeyboard = BitConverter.ToUInt32(TabBytes, 276)
'Entier DureeClick = 4 bytes
DureeClick = BitConverter.ToUInt32(TabBytes, 280)
'Tableau de caractères Application = 260 * 2 bytes
For i = 0 To 259
Application(i) = BitConverter.ToChar(TabBytes, 284 + (2 * i))
Next
'Tableau de caractères Paramètres = 260 * 2 bytes
For i = 0 To 259
Parametres(i) = BitConverter.ToChar(TabBytes, 804 + (2 * i))
Next
Decode = True
Catch ex As Exception
Decode = False
End Try
End Function
Thomas.
"tdcrotty" <
[email protected]> a écrit dans le message de
Thanks,
SO is this a form of manually marshalling? Just send the
data as raw bytes and return raw bytes from the dll
functions?
td