Visual Basic - ¿Podeis probar esto?

Life is soft - evento anual de software empresarial
 
Vista:

¿Podeis probar esto?

Publicado por Alfonso (103 intervenciones) el 03/08/2005 14:04:11
Hola!!! ¿Podeis probar en vuestro Visual Basic este trozo de codigo? En mi Visual Basic me da error y se me cierra, quisiera saber si es mi pc o el codigo que no va bien. Decidme lo que sea. Gracias!!!!!!

Crea un formulario y añade este codigo:

Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Sub Form_Load()
On Error Resume Next
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'We're going to call an API-function, without declaring it!
Dim lb As Long, pa As Long
'map 'user32' into the address space of the calling process.
lb = LoadLibrary("user32")
'retrieve the address of 'SetWindowTextA'
pa = GetProcAddress(lb, "SetWindowTextA")
'Call the SetWindowTextA-function
CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
'unmap the library's address
FreeLibrary lb
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:¿Podeis probar esto?

Publicado por Mr. Sade (322 intervenciones) el 09/08/2005 12:04:29
No funciona porque SetWindowText() solo acepta dos parametros (8 bytes) y sin embargo CallWindowProc() esta empujando a la pila 4 parametros (16 bytes) lo que producira un desbalance en la pila por 8 bytes cuando la funcion SetWindowText() termine. SetWindowText() solo sacara de la pila 2 parametros lo que hace que los dos ultimos parametros que se empujaron se queden en la pila y causen un tremendo safarancho en la pobre pila del pobre programa.
prueba esto, funcionara porque SendMessage() usa 4 parametros (16 bytes)

Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Const WM_SETTEXT = &HC

Private Sub Form_Load()
On Error Resume Next
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'We're going to call an API-function, without declaring it!
Dim lb As Long, pa As Long
'map 'user32' into the address space of the calling process.
lb = LoadLibrary("user32")
'retrieve the address of 'SetWindowTextA'
pa = GetProcAddress(lb, "SendMessageA")
'Call the SetWindowTextA-function
CallWindowProc pa, Me.hWnd, WM_SETTEXT, 0&, "Hello!"
'unmap the library's address
FreeLibrary lb
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:¿Podeis probar esto?

Publicado por Alfonso (103 intervenciones) el 09/08/2005 16:49:07
Muchas gracias!!! Puedes darme mas informacion de la API: CallWindowProc.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar