|
-
Dec 3rd, 2002, 05:16 AM
#1
Thread Starter
Hyperactive Member
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:
Public Const WH_DEBUG = 9
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
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public hHook As Long
Public Function DebugProc(ncode As Integer, wParam As Long, lParam As Long) As Long
CallNextHookEx hHook, ncode, wParam, lParam
End Function
FORM
VB Code:
Private Sub Form_Load()
hHook = SetWindowsHookEx(WH_DEBUG, AddressOf DebugProc, 0&, GetCurrentThreadId())
End Sub
Private Sub Form_Unload(Cancel As Integer)
hHook = UnhookWindowsHookEx(hHook)
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
-
Dec 3rd, 2002, 05:17 AM
#2
Thread Starter
Hyperactive Member
I have simplified this code so it's really short. I hope everyone understands it, otherwise, just ask and I'll explain
-
Dec 4th, 2002, 03:49 AM
#3
Thread Starter
Hyperactive Member
Nobody able to help? it's just a SetWindowsHookEx function call. Somebody should be familiar with this API
-
Dec 4th, 2002, 05:07 AM
#4
Frenzied Member
Somebody is.
The debugproc definition you have is wrong. It should be thus:-
VB Code:
Public Function DebugProc(ByVal ncode As Integer,ByVal wParam As Long,ByVal lParam As Long) As Long
DebugProc = CallNextHookEx(hHook, ncode, wParam, lParam)
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
-
Dec 5th, 2002, 05:32 AM
#5
Thread Starter
Hyperactive Member
Well, I changed it, to what you were saying but it still crashes unfortunatly . But it was an error, tnx 4 noticing it
-
Dec 5th, 2002, 08:50 AM
#6
Frenzied Member
Also, don't use "As Any"...
VB Code:
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
-
Dec 5th, 2002, 08:52 AM
#7
Thread Starter
Hyperactive Member
It was in the API viewer defined like that :P
And it still crashes , am i doomed to fail in using callbacks or something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|