Ooops, sorry. My MouseHooks use Aaron Ballmans RB classes from a long time ago and they handle the callback and pass it to my function so the first parameter wasn’t in the declaration. This does work in Xojo 2014r2 - not tried any newer versions.
If it helps, here is some of the code that we are using:
[code]Protected Function InstallMouseHook(attachTo as Win32MouseHookHandler) As Boolean #If TargetWin32 Then
Declare Function SetWindowsHookExA Lib “User32” (hookType As Integer, proc As Ptr, instance As Integer, threadID As Integer) As Integer
Declare Function GetCurrentThreadId Lib “Kernel32” As Integer
If attachTo = Nil Then
If mMouseAttached_ <> Nil Then
mMouseAttached_ = attachTo
Const WH_MOUSE = 7
mMouseHookHandle_ = SetWindowsHookExA(WH_MOUSE, AddressOf MouseHookCallbackFunction, 0, GetCurrentThreadId)
Return mMouseHookHandle_ <> 0
Private Function MouseHookCallbackFunction(nCode as Integer, wParam as Integer, lParam as Integer) As Integer #If TargetWin32 Then
Declare Function CallNextHookEx Lib “User32” (hookHandle As Integer, code As Integer, wParam As Integer, lParam As Integer) As Integer
Dim result As Integer
result = 0
If nCode >= 0 And mMouseAttached_ <> Nil Then
result = mMouseAttached_.MouseProc(wParam, lParam)
If result = 0 Then
Return CallNextHookEx(mMouseHookHandle_, nCode, wParam, lParam)
needs to be a Shared Method of the Window or in a Module.
Thanks Kevin, the fact that you had working code spurred me on to double check everything.
At a guess your MouseHookCallbackFunction is in a Module which is why your version worked and mine doesn’t even though we have pretty much the same code.[/quote]
Glad you got it working. For a minute I was worried that Xojo had broken something.
The Install, Callback & Remove methods are in a module (with callback being private). The Install method accepts an interface that implements the MouseProc method. mMouseAttached_ is a private property within the module that stores the object passed into Install until the Remove method is called.
If you didn’t already know, you can only have one callback for each type of hook which can make them harder to deal with.