Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 201934 22 nov. 2005 à 20:57
j'ai trouvé ça, si ça peut t'aider:
VB6
has 3 undocumented functions. VarPtr, StrPtr, and ObjPtr.StrPtr returns
object of a string, VarPtr returns address of any other variable and
ObjPtr returns address of an object. In VB.Net these 3 functions are
abosolete but their functionality is still avaliable.
Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
Imports System.Runtime.InteropServices
Imports System.Text
Dim LongValue As Integer
Dim Str As String = "Adnan Samuel"
'A byte array
Dim ByteArray () As Byte
'Convert string to byte and copy to byte array
ByteArray = Encoding.Default.GetBytes(Str)
'Create Gchandle instance and pin variable required
Dim MyGC As GCHandle = GCHandle.Alloc(LongValue, GCHandleType.Pinned)
'get address of variable in pointer variable
Dim AddofLongValue As IntPtr = MyGC.AddrOfPinnedObject()
'Use copy method to copy array data to variables
'address with length specified(4)
Marshal.Copy (AddofLongValue, ByteArray, 0, 4)
'First read value of variable from its address
'in memory in order to use it
LongValue = Marshal.ReadInt32(AddofLongValue)
'Print to output window
Debug.WriteLine("Vlaue of LongValue is: " & LongValue)
'Free GChandle to avoid memory leaks
MyGC.Free()