Visual Basic

go-jump

Llamar a punteros desde VB6

Ésta es una forma de llamar punteros en VB6 sin usar ninguna API externa a VB, programada por Karcrack.

Option Explicit
 
Private Type SUBROUTINE
    lNull           As Long '// Must be 0
    lPtr            As Long
End Type
 
Private Declare Function GoSubReturn Lib "MSVBVM60" Alias "__vbaGosubReturn" (ByRef lpSubRoutine As Long) As Long
 
'---------------------------------------------------------------------------------------
' Procedure : GoToPtr
' Author    : Karcrack
' Date      : 08/05/2010
' Purpose   : GoTo a pointer
' Warning   : It's not a JMP, is a GoTo, so the execution of the program won't continue
'           where you made the GoTo...
'---------------------------------------------------------------------------------------
'
Public Sub GoToPtr(ByVal lPtr As Long)
    Dim tSubRoutine As SUBROUTINE
 
    tSubRoutine.lPtr = lPtr
    Call GoSubReturn(VarPtr(tSubRoutine))
End Sub

Hay que tener cuidado con el puntero al cual llamamos, pues debido a que el Stack se deforma para hacer el salto no se puede volver al lugar desde el cual se llamo a la funcion.

Ejemplo de uso:

Sub Main()
    Call GoToPtr(gP(AddressOf RMain))
End Sub
 
Function gP(ByVal lPtr As Long) As Long
    gP = lPtr
End Function
 
Sub RMain()
    MsgBox "HOLA"
    End
End Sub

Gracias a Karcrack por el código.

Más >