Jump to content

Recommended Posts

Posted (edited)

When I use DllCallbackRegister zero is returned and @error is set to three.  The helpfile doesn't explain the @error.  Searching the forum reveals that no one else seems to have this same problem as far as I could see.  Here is my code:

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include <Misc.au3>

_Singleton(@ScriptName)

#include <WinAPI.au3>

Global Const $hStub_MouseProc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")

Switch $hStub_MouseProc
    Case 0
        ConsoleWrite("$hStub_MouseProc: " & $hStub_MouseProc & " @error: " & @error & @CRLF)
        Exit
EndSwitch

Global Const $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), _WinAPI_GetModuleHandle(0))

OnAutoItExitRegister("cleanup")

Do
    Sleep(10)
Until False

Func _Mouse_Proc(Const $nCode, Const $wParam, Const $lParam)
    Switch $nCode >= 0
        Case True
            ConsoleWrite("$nCode: " & $nCode & @CRLF)
    EndSwitch

    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

Func cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_MouseProc)
EndFunc

Windows 7 x64 -- AutoIt 3.3.9.5 & Stable

Edited by jaberwocky6669
Posted

Try... '_Mouse_Pro', 'long', 'int;wparam;lparam' as stated on MSDN.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

jaberwocky,

As guinness advised

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include <Misc.au3>

_Singleton(@ScriptName)

#include <WinAPI.au3>

Global Const $hStub_MouseProc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")

Switch $hStub_MouseProc
    Case 0
        ConsoleWrite("$hStub_MouseProc: " & $hStub_MouseProc & " @error: " & @error & @CRLF)
        Exit
EndSwitch

Global Const $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), _WinAPI_GetModuleHandle(0))

OnAutoItExitRegister("cleanup")

Do
    Sleep(10)
Until False

Func _Mouse_Proc($ncode,$wParam,$lParam)
    Switch $nCode >= 0
        Case True
            ConsoleWrite("$nCode: " & $nCode & @CRLF)
    EndSwitch

    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

Func cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_MouseProc)
EndFunc

kylomas

edit:  Se the Help file and this link

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

I've never seen anything like this.  It works with Kylomas' example.  I've done it like this before.  When I modify original script to match Kylomas' it doesn't work.  Yet, when I copy and paste Kylomas' script then it works.

Thanks for the help!

Posted (edited)

Here is the latest version of my script that did not work:

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include <Misc.au3>

_Singleton(@ScriptName)

#include <WinAPI.au3>

Global Const $mouse_proc_callback = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")

Switch $mouse_proc_callback
    Case 0
        ConsoleWrite("$mouse_proc_callback: " & $mouse_proc_callback & " @error: " & @error & @CRLF)
        Exit
EndSwitch

Global Const $hook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($mouse_proc_callback), _WinAPI_GetModuleHandle(0))

OnAutoItExitRegister("cleanup")

Do
    Sleep(10)
Until False

Func _Mouse_Proc(Const $code, Const $w_param, Const $l_param)
    Switch $code >= 0
        Case True
            Switch $w_param
                Case $WM_LBUTTONDOWN
                    ConsoleWrite("$WM_LBUTTONDOWN" & @CRLF)

                Case $WM_LBUTTONUP
                    ConsoleWrite("$WM_LBUTTONUP" & @CRLF)

                Case $WM_MOUSEMOVE
                    ConsoleWrite("$WM_MOUSEMOVE" & @CRLF)

                Case $WM_MOUSEWHEEL
                    ConsoleWrite("$WM_MOUSEWHEEL" & @CRLF)

                Case $WM_MOUSEHWHEEL
                    ConsoleWrite("$WM_MOUSEHWHEEL" & @CRLF)

                Case $WM_RBUTTONDOWN
                    ConsoleWrite("$WM_RBUTTONDOWN" & @CRLF)

                Case $WM_RBUTTONUP
                    ConsoleWrite("$WM_RBUTTONUP" & @CRLF)
            EndSwitch

            Return 0
        Case False
            Return _WinAPI_CallNextHookEx($hook, $code, $w_param, $l_param)
    EndSwitch
EndFunc

Func cleanup()
    _WinAPI_UnhookWindowsHookEx($hook)
    DllCallbackFree($mouse_proc_callback)
EndFunc

Compared to Kylomas' version that does work:

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include <Misc.au3>

_Singleton(@ScriptName)

#include <WinAPI.au3>

Global Const $hStub_MouseProc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")

Switch $hStub_MouseProc
    Case 0
        ConsoleWrite("$hStub_MouseProc: " & $hStub_MouseProc & " @error: " & @error & @CRLF)
        Exit
EndSwitch

Global Const $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), _WinAPI_GetModuleHandle(0))

OnAutoItExitRegister("cleanup")

Do
    Sleep(10)
Until False

Func _Mouse_Proc($ncode,$wParam,$lParam)
    Switch $nCode >= 0
        Case True
            ConsoleWrite("$nCode: " & $nCode & @CRLF)
    EndSwitch

    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

Func cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_MouseProc)
EndFunc

 This seems like high strangeness to me.

Edited by jaberwocky6669
Posted

I can see the problem, instead of Return 0 you should be calling the next hook. Also my advice still stands correct. You should ideally change it to that.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Like this?

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include <Misc.au3>

_Singleton(@ScriptName)

#include <WinAPI.au3>

Global Const $mouse_proc_callback = DllCallbackRegister("_Mouse_Proc", "long", "int;wparam;lparam")

Switch $mouse_proc_callback
    Case 0
        ConsoleWrite("$mouse_proc_callback: " & $mouse_proc_callback & " @error: " & @error & @CRLF)
        Exit
EndSwitch

Global Const $hook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($mouse_proc_callback), _WinAPI_GetModuleHandle(0))

OnAutoItExitRegister("cleanup")

Do
    Sleep(10)
Until False

Func _Mouse_Proc(Const $code, Const $w_param, Const $l_param)
    Switch $code >= 0
        Case True
            Switch $w_param
                Case $WM_LBUTTONDOWN
                    ConsoleWrite("$WM_LBUTTONDOWN" & @CRLF)

                Case $WM_LBUTTONUP
                    ConsoleWrite("$WM_LBUTTONUP" & @CRLF)

                Case $WM_MOUSEMOVE
                    ConsoleWrite("$WM_MOUSEMOVE" & @CRLF)

                Case $WM_MOUSEWHEEL
                    ConsoleWrite("$WM_MOUSEWHEEL" & @CRLF)

                Case $WM_MOUSEHWHEEL
                    ConsoleWrite("$WM_MOUSEHWHEEL" & @CRLF)

                Case $WM_RBUTTONDOWN
                    ConsoleWrite("$WM_RBUTTONDOWN" & @CRLF)

                Case $WM_RBUTTONUP
                    ConsoleWrite("$WM_RBUTTONUP" & @CRLF)
            EndSwitch
    EndSwitch

    Return _WinAPI_CallNextHookEx($hook, $code, $w_param, $l_param)
EndFunc

Func cleanup()
    _WinAPI_UnhookWindowsHookEx($hook)
    DllCallbackFree($mouse_proc_callback)
EndFunc
Posted
  On 5/12/2013 at 7:44 PM, jaberwocky6669 said:

OK, it was because I was setting the parameters for _Mouse_Proc to Const!

 

Yes, was that not obvious?   The MSDN doc is very specific about how and when to return and/or call the next hook.  Have you read it?

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted (edited)

No, it isn't obvious.  Chill please.  I don't see why I can't set the parameters to my own UDF to Const though.

"The MSDN doc is very specific about how and when to return and/or call the next hook.  Have you read it?" 

What does that have to do with setting parameters to const?

Edited by jaberwocky6669
Posted (edited)

I did see the Const and of course wondered that too, but didn't think it would make a blind bit of difference as they're being passed as values and not a references.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Hmmm...communication fails miserably in this medium...

What I was thinking when I posted that was that I should have pointed this out specifically.  When I re-read it I was afraid that you would take it critically.

The return comment refers specifically to what guinness is warning you about.

kylomas

edit: additional info

  Quote

 I don't see why I can't set the parameters to my own UDF to Const though.

 

 

Because CONST vars cannot change, the parms to this procedure change with every call.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

You don't have to edit the title anymore. Just select the button "mark solved" in the post that helped the most.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • Solution
Posted (edited)

Probably neither.

  On 5/12/2013 at 8:17 PM, jaberwocky6669 said:

No, it isn't obvious.  Chill please.  I don't see why I can't set the parameters to my own UDF to Const though.

"The MSDN doc is very specific about how and when to return and/or call the next hook.  Have you read it?" 

What does that have to do with setting parameters to const?

AutoIt doesn't allow the use of any keywords (const, byref, ...) for callback functions parameters.

Edited by trancexx

♡♡♡

.

eMyvnE

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...