Re: System-wide hooking, VB+ASM
- From: erewhon@xxxxxxxxxx (J French)
- Date: Fri, 3 Jun 2005 08:26:33 +0000 (UTC)
On Thu, 2 Jun 2005 16:45:09 -0700, "Karl E. Peterson" <karl@xxxxxxxx>
wrote:
>J French wrote:
>>> Unless you have, or are aware of, a real example of that then you
>>> can't say it is possible. Do you have an example of a system-wide
>>> hook using just VB? In other words, not using additional tools not
>>> provided with VB and/or not documented in the MSDN.
>>
>> I have just done some experiments (with the usual horrendous crashes)
>> and have /not/ managed to make it work reliably.
>>
>> A system wide keyboard hook installs and uninstalls Ok, but I got
>> crashes when the DLL was being mapped into another process's address
>> space.
>
>I can't seem to force the crash here. Got the hook installing just fine, but not
>reacting at all to other processes. I wonder if that's an OS difference? (Running
>W2K/SP4 here.)
hHook = SetWindowsHookEx(WH_KEYBOARD,
AddressOf KeyboardProc,
App.hInstance, 0)
The last parameter needs to be App.ThreadID for a hook that is
restricted to the current App
- if it is 0 then the hook is system wide
Sounds like it is not 0 - I got that running perfectly
>> Since the mapping takes place 'on demand' (ie: when you press a key
>> over another App) it is difficult to tell whether it is the mapping
>> that is causing the crash, or the actual hook routine.
>My hunch is, in fact I'm well-near certain, that you'd need to initialize the runtime
>on entrance.
Hmm.. that sounds problematical
BTW I tried setting the DLL's startup mode to both Sub Main() and
'None'
The 'None' seemed less drastic on crashing
Also I'm using VB5
Just thinking out loud, the DLL must be capable of initializing the
run time itself, as one can use a VB DLL happily from another
language, my guess is that is done by the LibMain routine
Here is a bit from www.masm32.com
; ####################################################
LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD
szText LmTitle,"tstdll's LibMain Function"
.if reason == DLL_PROCESS_ATTACH
szText ATTACHPROCESS,"PROCESS_ATTACH"
invoke MessageBox,NULL,ADDR ATTACHPROCESS,addr
LmTitle,MB_OK
return TRUE
; -----------------------------
; If error at startup, return 0
; System will abort loading DLL
; -----------------------------
.elseif reason == DLL_PROCESS_DETACH
szText DETACHPROCESS,"PROCESS_DETACH"
invoke MessageBox,NULL,addr DETACHPROCESS,addr
LmTitle,MB_OK
.elseif reason == DLL_THREAD_ATTACH
szText ATTACHTHREAD,"THREAD_ATTACH"
invoke MessageBox,NULL,addr ATTACHTHREAD,addr
LmTitle,MB_OK
.elseif reason == DLL_THREAD_DETACH
szText DETACHTHREAD,"THREAD_DETACH"
invoke MessageBox,NULL,addr DETACHTHREAD,addr
LmTitle,MB_OK
.endif
ret
LibMain Endp
In the Win32 Programmer's Reference Help File the topic
How to Port a 16-bit DLL to a Win32 DLL
has some clues on this.
I can't quite get my head around the initialization sequence, but I am
certain that LibMain is called both on normal LoadLibrary and when it
is being mapped into another process. I've seen that in Delphi.
.
- Follow-Ups:
- Re: System-wide hooking, VB+ASM
- From: Jonathan Wood
- Re: System-wide hooking, VB+ASM
- From: Jonathan Wood
- Re: System-wide hooking, VB+ASM
- References:
- Re: System-wide hooking, VB+ASM
- From: J French
- Re: System-wide hooking, VB+ASM
- From: Sam Hobbs
- Re: System-wide hooking, VB+ASM
- From: J French
- Re: System-wide hooking, VB+ASM
- From: Karl E. Peterson
- Re: System-wide hooking, VB+ASM
- Prev by Date: Re: Current User
- Next by Date: Re: Using Visual Basic to Write System-Wide Hooks
- Previous by thread: Re: System-wide hooking, VB+ASM
- Next by thread: Re: System-wide hooking, VB+ASM
- Index(es):
Relevant Pages
|