Re: System-wide hooking, VB+ASM
- From: erewhon@xxxxxxxxxx (J French)
- Date: Sun, 5 Jun 2005 09:24:57 +0000 (UTC)
On Sat, 4 Jun 2005 08:21:41 -0700, "Sam Hobbs"
<samuel@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>"J French" <erewhon@xxxxxxxxxx> wrote in message
>news:42a17489.8343638@xxxxxxxxxxxxxxxxxxx
>>
>> Sure - it is just a lashup job - I'm not proud of it
>>
>> www.jerryfrench.co.uk/hooktest.zip
>
>The CallNextHookEx function needs the handle to the current hook, which is
>returned by the SetWindowsHookEx function used to set the hook. You are
>doing that, except the handle is not available in any other address space.
>When the DLL is injected into the other address spaces, an uninitialized
>value (probably zero) will be used for the hook handle (hHook). I don't know
>how much of a problem that is, but it could be a problem.
That had me puzzled at first.
However I can assure you that it works in Delphi
The reason (I believe) is that only the /first/ instance of the DLL
needs to CallNextHook
- in other instances it is effectively a 'dummy'
<snip>
>> Alhough delving deeper, Delphi has something called _InitLib that does
>> the same.
>>
>> I just wonder whether that DllMain that he talks about is a red
>> herring.
>>
>> This is getting quite interesting.
>Look up DllMain in the SDK documentation. It's prototype is:
>
> BOOL WINAPI DllMain(
> HINSTANCE hinstDLL, // handle to the DLL module
> DWORD fdwReason, // reason for calling function
> LPVOID lpvReserved // reserved
> );
Yes - I've been there
>The DllMain is called by Windows twice for each process the DLL is used for
>and twice for each thread. The fdwReason parameter indicates what the call
>is for. In a DLL I wrote using C++ that has system-wide hooks in it, the
>only thinkg my DllMain does is to store the hinstDLL when fdwReason is
>DLL_PROCESS_ATTACH. If I were to get the DLL's instance handle using
>something else, then I don't need the DllMain in that DLL.
>I don't know if VB uses a DLL entry point (called DllMain, LibMain or
>whatever) but it probably does. We don't know what it is doing but it could
>be causing a problem somehow.
My guess (and it is just a guess) is that all DLLs have this as a
standard entry point.
A bit of further digging and I've found that LibMain is the Win16
entry point and DllMain is the Win 32 entry point.
I suppose the next test is to do a LoadLibrary on a VB DLL from
another language.
.
- Follow-Ups:
- Re: System-wide hooking, VB+ASM
- From: Sam Hobbs
- 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
- From: J French
- Re: System-wide hooking, VB+ASM
- From: Jonathan Wood
- Re: System-wide hooking, VB+ASM
- From: J French
- Re: System-wide hooking, VB+ASM
- From: Sam Hobbs
- Re: System-wide hooking, VB+ASM
- Prev by Date: Re: GetDiskFreeSpace
- Next by Date: Re: System-wide hooking, VB+ASM
- Previous by thread: Re: System-wide hooking, VB+ASM
- Next by thread: Re: System-wide hooking, VB+ASM
- Index(es):
Relevant Pages
|