CallWndProc Doesn't work

  • Thread starter Thread starter Arsium
  • Start date Start date
A

Arsium

Guest
As the title says , I tried to call this procedure (in vbnet) and seems doesn't work


Here is class of the hook :


Public Class MessagesHooking
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Public Shared Function SetWindowsHookEx(ByVal id As Integer, ByVal callback As CallWndProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr

End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Public Shared Function GetModuleHandle(ByVal name As String) As IntPtr

End Function

<StructLayout(LayoutKind.Sequential)>
Private Structure CWPSTRUCT
Public lParam
Public wParam
Public message
Public Hwnd As IntPtr
End Structure

Public Delegate Function CallWndProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr


<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Public Shared Function UnhookWindowsHookEx(ByVal hook As IntPtr) As Boolean

End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Private Shared Function CallNextHookEx(ByVal hook As IntPtr, ByVal nCode As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr

End Function

Public Shared ptrHook As IntPtr
Private objMouseProcess As CallWndProc

Public Shared Function captureKey(ByVal nCode As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr

If nCode >= 0 Then

Dim objKeyInfo As CWPSTRUCT = CType(Marshal.PtrToStructure(lp, GetType(CWPSTRUCT)), CWPSTRUCT)

MessageBox.Show(nCode.ToString)

End If

Return CallNextHookEx(ptrHook, nCode, wp, lp)
End Function
End Class



And here is how I call the hook :


Dim objCurrentModule As ProcessModule = Process.GetCurrentProcess().MainModule
Dim objKeyboardProcess As New MessagesHooking.CallWndProc(AddressOf MessagesHooking.captureKey)
Dim ptrHook = MessagesHooking.SetWindowsHookEx(4, objKeyboardProcess, MessagesHooking.GetModuleHandle(objCurrentModule.ModuleName), 0)
Do you have any idea ?

Continue reading...
 
Back
Top