Results 1 to 5 of 5

Thread: Problems in Hooks

  1. #1

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Cool Problems in Hooks

    Hello everybody....
    I am trying to set a global CBTProc Hook..
    I've written a Hook procedure and set it with the help of SetWindowsHookEX API function...
    This Hook procedure calls, it means hook is set successfully.. but i can't figure out why it is giving illegal operation message..i've done so many things.. but still helpless....
    Please Help!!!
    Anyone knows how to set up the hooks in VB without errors???
    MOIN.

  2. #2
    DerFarm
    Guest
    Kinda tough with no code.

  3. #3
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Try to debug your code and locate exact point of error. Most of
    the times it turns out to be some wrong assignment or very small
    but BIG mistake.

  4. #4
    Crunchy Cat
    Guest
    Hi, there is not really enough data to give you an accurate
    diagnosis, but I would recommend the following:

    * Ensure you are calling the next hook in the hook chain
    after you are finished processing the current callback.
    * Ensure your callback is not changing any data that is
    not meant to be changed.
    * Ensure your callback is implemented in a standard Win32
    compliant DLL (especially if you are hooking into other
    processes).

    One thing that I like to do when debugging hooking problems
    is put Beep () statements in my callback when certain conditions
    occur. This helps me understand the natural flow of events in
    the absence of a debugger.

    -CC

  5. #5
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    In lieu of Beep statements, you can use the OutputDebugString API call - this can fire debug messages from a compiled exe that you can view using DBMON or a similar debug monitor tool.

    If you are getting a crash when your CBTProc is called, the most likely thing is that your procedure definition is wrong - wrong return type or parameter type(s)?

    Try the following:
    VB Code:
    1. '\\ [VB_HOOKCBTPROC]------------------------------------------------------
    2. '\\ typedef LRESULT (CALLBACK* HOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
    3. '\\ code - type of hook,
    4. '\\ Wparam, Lparam - message specific
    5. '\\ lMsgRet = The message to pass to the calling code
    6. '\\ --------------------------------------------------------------------------------
    7. '\\ (c) 2001 - Merrion Computing.  All rights  to use, reproduce or publish this code reserved
    8. '\\ Please check http://www.merrioncomputing.com for updates.
    9. '\\ --------------------------------------------------------------------------------
    10. Public Function VB_HOOKCBTPROC(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    11.  
    12. On Local Error Resume Next
    13.  
    14. Dim Params() As Variant
    15. Dim lret As Long
    16. Dim lMsgRet As Long
    17.  
    18. '\\ Note: If the code passed in is less than zero, it must be passed direct to the next hook proc
    19. If Code < 0 Then
    20.     VB_HOOKCBTPROC = CallNextHookEx(Eventhandler.HookIdByType(WH_CBT), Code, wParam, lParam)
    21. End If
    22.  
    23. '\\ Do whatever with the message here.......
    24.  
    25.  
    26. '\\ Pass this message on to the next hook proc in the chain (if any)
    27. lret = CallNextHookEx(Eventhandler.HookIdByType(WH_CBT), Code, wParam, lParam)
    28. If Err.LastDllError > 0 Then
    29.    Debug.Print Err.LastDllError  & " in VB_HOOKCBTPROC "
    30. End If
    31.  
    32. '\\ If the message isn't cancelled, return the next hook's message...
    33. If Not (lMsgRet) Then
    34.     '\\ Return value to calling code....
    35.     VB_HOOKCBTPROC = lret
    36. End If
    37.  
    38. End Function

    HTH,
    Duncan
    Last edited by MerrionComputin; Feb 22nd, 2002 at 05:25 AM.
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width