1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim bb As Integer = 8
Dim ptr As IntPtr = Marshal.AllocHGlobal(4) ' 4 parce que la taille de Integer est 4 octets
Marshal.WriteInt32(ptr, bb)
Dim alias_de_bb As Integer = Marshal.ReadInt32(ptr)
alias_de_bb += 15
MsgBox(alias_de_bb.ToString) 'et là ça doit me donner un message avec : 23
MsgBox(bb.ToString)
Marshal.FreeHGlobal(ptr) 'n'oublie pas de liberer le pointeur ptr utilisé
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim MyInt32 As Integer = 0
Dim MyPtr As IntPtr = MyInt32
End Sub
End Class |
Partager