VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Using real pointers in VB

by Stephan Kirchmaier (8 Submissions)
Category: Coding Standards
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

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

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

Rate Using real pointers in VB

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

Download this snippet    Add to My Saved Code

Using real pointers in VB Comments

No comments have been posted about Using real pointers in VB. Why not be the first to post a comment about Using real pointers in VB.

Post your comment

Subject:
Message:
0/1000 characters