If you look at MSVBVM60's export table you'll see there's no functions called StrPtr() or ObjPtr()... Those are just
macros of VarPtr()... So in theory you'd be able to replace those
macros but sadly
is not posible with StrPtr().
You cannot replace StrPtr() because VB6 always create a copy of the string you're passing to an external function... so if you try to pass the string to the MulDiv() func it will recieve a copy of the string, therefore you'll be getting the pointer to a copied string that after the API call will be deleted from memory. Here you got a sample that shows
it won't work:
'KERNEL32
Private Declare Function VarPtr__ Lib "KERNEL32" Alias "MulDiv" (ByRef a As Any, Optional ByVal b As Long = 1, Optional ByVal c As Long = 1) As Long
'MSVBVM60
Private Declare Sub GetMem4 Lib "MSVBVM60" (ByVal lPtr As Long, ByRef ret As Long)
'USER32
Private Declare Function MessageBoxW Lib "USER32" (ByVal hWnd As Long, ByVal lpText As Long, ByVal lpCaption As Long, ByVal wType As Long) As Long
Private Sub Form_Load()
Dim cadena As String
Dim ptr1 As Long
Dim ptr2 As Long
cadena = "karcrack"
ptr1 = StrPtr(cadena)
'StrPtr__
Call GetMem4(VarPtr__(cadena) + 4, ptr2)
MsgBox (ptr1 = ptr2)
Call MessageBoxW(0, ptr2, 0, 0)
Call MessageBoxW(0, ptr1, 0, 0)
End Sub
About ObjPtr() there's no problem about it... just need to change ByRef to ByVal because of the VB6 object instance creator...
'KERNEL32
Private Declare Function ObjPtr__ Lib "KERNEL32" Alias "MulDiv" (ByVal a As Any, Optional ByVal b As Long = 1, Optional ByVal c As Long = 1) As Long
Private Sub Form_Load()
Dim ptr1 As Long
Dim ptr2 As Long
ptr1 = ObjPtr(Me)
ptr2 = ObjPtr__(Me)
MsgBox (ptr1 = ptr2)
End Sub