Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: BlackZeroX en 27 Marzo 2010, 01:47 am



Título: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 01:47 am

Este codigo que les dejo me arreglo una duda que tenia la cual me la respondio Google a una liga interesante ( Almenos para mi xP )

intentaba hacer algo similar a esto:

Código
  1.  
  2. Private Sub Form_Load()
  3. Dim Args()          As Variant
  4.    ReDim Args(0 To 1)
  5.    Args(0) = "hola Mundo"
  6.    Args(1) = "12"
  7.    CallByName Me, "Mensaje", VbMethod, Args()
  8. End Sub
  9.  
  10. Public Sub mensaje(mensaje As String, Optional hola As Long)
  11.    MsgBox mensaje, vbOKOnly, hola
  12. End Sub
  13.  
  14.  

pero no daba y google me respodio:

http://www.devx.com/tips/Tip/15422

Código
  1.  
  2. ' Required for use in VB5!
  3. Public Enum VbCallType
  4. VbMethod = 1
  5. VbGet = 2
  6. VbLet = 4
  7. VbSet = 8
  8. End Enum
  9.  
  10. Public Function CallByNameEx(Obj As Object, _
  11. ProcName As String, CallType As VbCallType, _
  12. Optional vArgsArray As Variant)
  13. Dim oTLI As Object
  14. Dim ProcID As Long
  15. Dim numArgs As Long
  16. Dim i As Long
  17. Dim v()
  18.  
  19. On Error GoTo Handler
  20.  
  21. Set oTLI = CreateObject("TLI.TLIApplication")
  22. ProcID = oTLI.InvokeID(Obj, ProcName)
  23.  
  24. If IsMissing(vArgsArray) Then
  25. CallByNameEx = oTLI.InvokeHook( _
  26. Obj, ProcID, CallType)
  27. End If
  28.  
  29. If IsArray(vArgsArray) Then
  30. numArgs = UBound(vArgsArray)
  31. ReDim v(numArgs)
  32. For i = 0 To numArgs
  33. v(i) = vArgsArray(numArgs - i)
  34. Next i
  35. CallByNameEx = oTLI.InvokeHookArray( _
  36. Obj, ProcID, CallType, v)
  37. End If
  38. Exit Function
  39.  
  40. Handler:
  41. Debug.Print Err.Number, Err.Description
  42. End Function
  43.  
  44.  

con lo cual ahora el CallByName bueno mejor dicho CallByNameEx acepta ahora expresiones de este tipo:

Código
  1.  
  2. Call CallByNameEx(Me, "xx", VbMethod, x)
  3. Call CallByNameEx(Me, "xx", VbMethod, Array(1, 2))  
  4. Result=CallByNameEx(Me, "xx", VbMethod, x)
  5.  
  6.  

siendo que antes array() o pasandole un vector a CallByName No servia

Código
  1.  
  2. Private Sub Form_Load()
  3. Dim Args()          As Variant
  4.    ReDim Args(0 To 1)
  5.    Args(0) = "hola Mundo"
  6.    Args(1) = "12"
  7.    CallByNameEx Me, "Mensaje", VbMethod, Args()
  8. End Sub
  9.  
  10. Public Sub mensaje(mensaje As String, Optional hola As Long)
  11.    MsgBox mensaje, vbOKOnly, hola
  12. End Sub
  13.  
  14.  

Sangrienta Luna Infernal!¡.


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: LeandroA en 27 Marzo 2010, 03:15 am
Interesante che, que aplicación sera TLI? saves cual es la refencia¿?

Saludos.


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 06:45 am
TypeLib Information

TLBInf32.dll

Sangriento Infierno Lunar.


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 06:49 am

Agregando la referencia... TypeLib Information:

Código
  1.  
  2. ' Required for use in VB5!
  3. Public Enum VbCallType
  4.    VbMethod = 1
  5.    VbGet = 2
  6.    VbLet = 4
  7.    VbSet = 8
  8. End Enum
  9. Public Function CallByNameEx(Obj As Object, ProcName As String, CallType As VbCallType, Optional vArgsArray As Variant)
  10. On Error GoTo Handler
  11. Dim oTLI            As TLIApplication '    //  Set oTLI = CreateObject("TLI.TLIApplication")
  12. Dim ProcID          As Long
  13. Dim numArgs         As Long
  14. Dim i               As Long
  15. Dim v()             As Variant
  16.  
  17.    Set oTLI = New TLIApplication
  18.    If Not oTLI Is Nothing Then
  19.        ProcID = oTLI.InvokeID(Obj, ProcName)
  20.        If IsMissing(vArgsArray) Then
  21.            CallByNameEx = oTLI.InvokeHook(Obj, ProcID, CallType)
  22.        End If
  23.        If IsArray(vArgsArray) Then
  24.            numArgs = UBound(vArgsArray)
  25.            ReDim v(numArgs)
  26.            For i = 0 To numArgs
  27.                v(i) = vArgsArray(numArgs - i)
  28.            Next i
  29.            CallByNameEx = oTLI.InvokeHookArray(Obj, ProcID, CallType, v)
  30.        End If
  31.    End If
  32. Exit Function
  33.  
  34. Handler:
  35.    Debug.Print Err.Number, Err.Description
  36. End Function
  37.  
  38.  

Sangriento Infierno Lunar!¡.


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: Karcrack en 27 Marzo 2010, 13:03 pm
Tambien podrias hacer esto, no?
Código
  1. Private Sub Form_Load()
  2.    Dim vParams(1)  As Variant
  3.  
  4.    vParams(0) = "Hi ho"
  5.    vParams(1) = 1500
  6.    CallByName Me, "Mensaje", VbMethod, vParams()
  7. End Sub
  8.  
  9. Public Sub Mensaje(ByRef vParams() As Variant)
  10.    Call MsgBox(vParams(0), , vParams(1))
  11. End Sub


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: seba123neo en 27 Marzo 2010, 15:06 pm
Tambien podrias hacer esto, no?
Código
  1. Private Sub Form_Load()
  2.    Dim vParams(1)  As Variant
  3.  
  4.    vParams(0) = "Hi ho"
  5.    vParams(1) = 1500
  6.    CallByName Me, "Mensaje", VbMethod, vParams()
  7. End Sub
  8.  
  9. Public Sub Mensaje(ByRef vParams() As Variant)
  10.    Call MsgBox(vParams(0), , vParams(1))
  11. End Sub

si, yo tambien pense eso, pero el tema aca es que al pasarle el, array te pase cada indice del mismo al parametro correspondiente.

saludos.


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 17:59 pm
Tambien podrias hacer esto, no?
Código
  1. Private Sub Form_Load()
  2.    Dim vParams(1)  As Variant
  3.  
  4.    vParams(0) = "Hi ho"
  5.    vParams(1) = 1500
  6.    CallByName Me, "Mensaje", VbMethod, vParams()
  7. End Sub
  8.  
  9. Public Sub Mensaje(ByRef vParams() As Variant)
  10.    Call MsgBox(vParams(0), , vParams(1))
  11. End Sub

la cosa que si algun parametro es distinto a variant por ejemplo una revoltura de variados parametros de distintos tipos NO FUNCIONA y este era mi problema y no me hubiera gustado estar convirtiendo dentro cada parametro al real.


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: Karcrack en 27 Marzo 2010, 18:24 pm
He estado investigando mas sobre TLI32 y es muy muy interesante... >:D

Código:
http://support.microsoft.com/kb/q224331/

 :D


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 19:01 pm
He estado investigando mas sobre TLI32 y es muy muy interesante... >:D

Código:
http://support.microsoft.com/kb/q224331/

 :D

No dije yo esto pero...:

Puedes obtener las funciones/procesos/Propiedades y sus parametros con sus tipos respectivos...

Sangrienta Luna Infernal!¡.


Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: LeandroA en 28 Marzo 2010, 05:54 am
che me gusto esa libreria mirando la ayuda vi que se pueden enumerar todas las constantes eventos funcion etc de una librerira

Código:
Private Sub Form_Load()

    Dim SIType As SearchItem
    Dim SIMember As SearchItem
    With TypeLibInfoFromFile("msvbvm60.dll")
      .SearchDefault = tliStConstants
      For Each SIType In .GetTypes
        For Each SIMember In .GetMembers(SIType.SearchData)
          Debug.Print SIMember, _
            .GetMemberInfo(SIType.SearchData, SIMember.InvokeKinds, SIMember.MemberId).Value
        Next
      Next
    End With

End Sub