pero no hookea mas que los mensajes al thread de la dll.
Código:
'DLL activeX
'En un modulo
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Type T_Hookguay
idHook As Long
lpfn As Long
hmod As Long
dwThreadId As Long
hhooKRET As Long
End Type
Public Hook As T_Hookguay 'ale punterete a la extructura
Public Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _
As Long
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const GWL_HINSTANCE = (-6)
Public Const WH_CBT = 5
Public Const HCBT_ACTIVATE = 5
Const HCBT_CREATEWND As Long = 3
Public Const WM_KEYFIRST = &H100
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Public Function Formas(ByVal modd As Long) As Long
Dim pp As Long
Hook.lpfn = Adresspackajing(AddressOf Interceptor) 'whao! un puntero a una funcion..hay k hoderse XD
Hook.idHook = WH_CBT 'podiamos haberlo pasado directamente ..pero asi esto os puede servir para
pp = FindWindow(ByVal 0&, ByVal 0&)
Hook.hmod = GetWindowLong(pp, GWL_HINSTANCE)
Hook.dwThreadId = Shell("notepad.exe")
Hook.hhooKRET = SetWindowsHookEx(Hook.idHook, Hook.lpfn, Hook.hmod, hook.dwThreadId)
End Function
Public Function Interceptor(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lpClassName As String, r As Long, rr As Long, ra As Long
ra = GetWindowThreadProcessId(wParam, rr)
If Hook.hhooKRET < 0 Then
'call the next hook
Interceptor = CallNextHookEx(Hook.hhooKRET, lMsg, wParam, ByVal lParam)
Else
If rr = Hook.dwThreadId Then
MsgBox ("siiiiiiiiiii")
End If
Interceptor = CallNextHookEx(Hook.hhooKRET, lMsg, wParam, ByVal lParam)
End If
End Function
Public Function Adresspackajing(ByVal Add As Long) As Long
Adresspackajing = Add
End Function
Código:
Option Explicit
' Las declaraciones de las funciones de la DLL
Declare Function Formas Lib "pr.dll" (ByVal modd As Long) As Long
Código:
'form Exe de donde llamamos a la Dll
Private Sub Form_Load()
Dim p As Long
p = Formas()
End Sub