Results 1 to 7 of 7

Thread: Callback errors

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    The Netherlands
    Posts
    403

    Callback errors

    Callbacks seem to be a really big problem to me. A couple of years ago everything went fine when I subclassed a control or something. But now I try to Debug my own thread and again my VB quits without errormessage:

    MODULE
    VB Code:
    1. Public Const WH_DEBUG = 9
    2.  
    3. 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
    4. Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    5. Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
    6. Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    7.  
    8. Public hHook As Long
    9.  
    10. Public Function DebugProc(ncode As Integer, wParam As Long, lParam As Long) As Long
    11. CallNextHookEx hHook, ncode, wParam, lParam
    12. End Function

    FORM
    VB Code:
    1. Private Sub Form_Load()
    2. hHook = SetWindowsHookEx(WH_DEBUG, AddressOf DebugProc, 0&, GetCurrentThreadId())
    3. End Sub
    4.  
    5. Private Sub Form_Unload(Cancel As Integer)
    6. hHook = UnhookWindowsHookEx(hHook)
    7. End Sub

    I hate it when it does quitting without errormessage. I think my code above is right but maybe one of you might see some errors
    There are 10 types of people, those who understand binary and those who don't

    http://merlijn.beyonix.net

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    The Netherlands
    Posts
    403
    I have simplified this code so it's really short. I hope everyone understands it, otherwise, just ask and I'll explain
    There are 10 types of people, those who understand binary and those who don't

    http://merlijn.beyonix.net

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    The Netherlands
    Posts
    403
    Nobody able to help? it's just a SetWindowsHookEx function call. Somebody should be familiar with this API
    There are 10 types of people, those who understand binary and those who don't

    http://merlijn.beyonix.net

  4. #4
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    Somebody is.

    The debugproc definition you have is wrong. It should be thus:-

    VB Code:
    1. Public Function DebugProc(ByVal ncode As Integer,ByVal wParam As Long,ByVal  lParam As Long) As Long
    2.  
    3. DebugProc = CallNextHookEx(hHook, ncode, wParam, lParam)
    4.  
    5. End Function

    Because otherwise you are getting the address of nCode, wparam and lParam and passing that out as the value to CallNextHookEx.

    Hope this helps,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    The Netherlands
    Posts
    403
    Well, I changed it, to what you were saying but it still crashes unfortunatly . But it was an error, tnx 4 noticing it
    There are 10 types of people, those who understand binary and those who don't

    http://merlijn.beyonix.net

  6. #6
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    Also, don't use "As Any"...

    VB Code:
    1. Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long,ByVal lParam As Long) As Long

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    The Netherlands
    Posts
    403
    It was in the API viewer defined like that :P

    And it still crashes , am i doomed to fail in using callbacks or something
    There are 10 types of people, those who understand binary and those who don't

    http://merlijn.beyonix.net

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