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