except for the _LL hook, SetWindowsHookEx must be using in a DLL. The DLL will be injected in other processes then your own and its methods are called in the context of those processes, you might need a shared section in the DLL to deal with this.
I have not been able to produce a good working example.
Two remarks:
- first, I think it is important that:
HINSTANCE hMod : should be the instance that was passed from DLLmain()
BOOL WINAPI DllMain(
__in HINSTANCE hinstDLL, <--- this instance
__in DWORD fdwReason,
__in LPVOID lpvReserved
);
- second:
#pragma data_seg("shared")
#pragma comment(linker, "/section:shared,rws")
HWND gTarget = 0; // it is required to initialize shared variables
#pragma data_seg()
if you do not initialize such a variable, it will be placed in the default data section, not in the shared section. The word "shared" is just a name of a section and has no function, the 'rws' part is what specifies the 'shared' property. Note that spaces in the "linker" string are not allowed, as it follows commandline syntax.
We need a good example of this usage!
(The "
Installing and Releasing Hook Procedures." section contains an incomplete example)