say i have made a dll for hooks. what's the best way to make the hook handle available to all instances of this dll so that the hookproc can call CallNextHookEx? do i have to do it with a shared section?
Posted on 2002-06-29 05:08:26 by cynix
In Windows, DLL code (as long as its not modified) is shared between all application, but the data is not. To have the same handle available to all application, you would, yes, have to use shared memory. Memory mapped files would be a good idea.
Posted on 2002-06-29 12:06:11 by comrade

In Windows, DLL code (as long as its not modified) is shared between all application
copy on write?


Memory mapped files would be a good idea.
but it seems quite slow...
Posted on 2002-06-29 22:48:48 by cynix
cynix, months ago I was thinking about the same problem. Finally I decided to use a shared section holding the hook handle. The hook handle is written to the shared section immediately after the call to SetWindowsHook.

How to write to a variable which is in dll? Safest way is to pass hHook to one of the dll's exported functions say Initialiser and let the dll function do the mov , hHook .
Posted on 2002-06-30 04:12:37 by C.Z.
cynix,
how is one instance of your dll going to be able to tell if another instance is already loaded and has the memory handle? What if another instance is already loaded, but has not implemented the hook yet?

I know how i would do it, just curious if you have thought of this yet :)
Posted on 2002-06-30 07:22:01 by sluggy
well, right now i'm using a named memory mapped file, so dll entry proc first tries OpenFileMapping and if that fails, CreateFileMapping. if mapping is opened then it MapViewOfFile, gets the handle of the hook, then Unmap. i just think it's such a waste to use a mapped file for a 4-byte value...
Posted on 2002-06-30 19:55:42 by cynix

What if another instance is already loaded, but has not implemented the hook yet?
the dll is loaded into every process _when_ i SetWindowsHookEx, so before i hook there shouldn't be "another instance" at all, only the one loaded by my exe, right?
Posted on 2002-06-30 19:57:25 by cynix
Just place the variables that are to be global to the DLL in a shared section in the DLL.
Posted on 2002-07-01 19:34:15 by Sephiroth3