Search Tools Links Login

Using real pointers in VB!


This code uses undocumented functions of VB that gives you a pointer to a string or a number!

Original Author: Stephan Kirchmaier

API Declarations

Private Declare Sub CopyMemByPtr Lib "kernel32" Alias _
"RtlMoveMemory" (ByVal lpTo As Long, ByVal lpFrom As Long, _
ByVal lLen As Long)

Code

Private Declare Sub CopyMemByPtr Lib "kernel32" Alias _
  "RtlMoveMemory" (ByVal lpTo As Long, ByVal lpFrom As Long, _
  ByVal lLen As Long)

Private Sub Form_Click()
  Dim a As Long, b As String, c As Long, d As String
  Dim i As Integer, j As Long, k As Integer, l As Long
  Dim u(2) As Byte, o As Long
  
  b = "HELLO!"
  d = Space(Len(b))
  i = 20
  u(0) = 23
  u(1) = 243
  u(2) = 124
  
  o = VarPtr(u(0))
  j = VarPtr(i)
  l = VarPtr(k)
  a = StrPtr(b)
  c = StrPtr(d)
  
  CopyMemByPtr o + 1, j, Len(u(0)) * 2
  CopyMemByPtr l, j, Len(i) * 2
  CopyMemByPtr c, a, Len(b) * 2
  
  MsgBox d & vbCr & k & vbCr & u(1)
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 95 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.