25#if ( _WIN32_WINNT < 0x0400 )
27 #define WH_KEYBOARD_LL 13
28 #define WH_MOUSE_LL 14
33 #define LLKHF_EXTENDED (KF_EXTENDED >> 8)
34 #define LLKHF_INJECTED 0x00000010
35 #define LLKHF_ALTDOWN (KF_ALTDOWN >> 8)
36 #define LLKHF_UP (KF_UP >> 8)
37 #define LLMHF_INJECTED 0x00000001
42 typedef struct tagKBDLLHOOKSTRUCT {
48 } KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;
53 typedef struct tagMSLLHOOKSTRUCT {
59 } MSLLHOOKSTRUCT, FAR *LPMSLLHOOKSTRUCT, *PMSLLHOOKSTRUCT;
71 #pragma comment(linker, "/section:.tnbwinhook,RWS")
72 #pragma data_seg(".tnbwinhook")
76 _SELECTANY HINSTANCE g_hInstance = NULL;
78 _SELECTANY DWORD g_dwThreadId = 0;
80 #define _WINHOOKMAC(NAME) \
81 _SELECTANY HHOOK s_hhk##NAME = NULL; \
82 static HHOOK Hook##NAME(bool b, HOOKPROC PF) { \
83 if ( ! b && s_hhk##NAME != NULL ){ \
84 ::UnhookWindowsHookEx(s_hhk##NAME); s_hhk##NAME = NULL; \
86 if ( b && s_hhk##NAME == NULL ){ \
87 s_hhk##NAME = SetWindowsHookEx(WH_##NAME, PF, g_hInstance, g_dwThreadId); \
92 _WINHOOKMAC( MSGFILTER )
93 _WINHOOKMAC( JOURNALRECORD )
94 _WINHOOKMAC( JOURNALPLAYBACK)
95 _WINHOOKMAC( KEYBOARD )
96 _WINHOOKMAC( GETMESSAGE )
97 _WINHOOKMAC( CALLWNDPROC )
99 _WINHOOKMAC( SYSMSGFILTER )
101 _WINHOOKMAC( HARDWARE )
104 _WINHOOKMAC( FOREGROUNDIDLE )
105 _WINHOOKMAC( CALLWNDPROCRET )
106 _WINHOOKMAC( KEYBOARD_LL )
107 _WINHOOKMAC( MOUSE_LL )
185 typedef HHOOK (*LPHOOKFUNC)(bool, HOOKPROC);
190 public: ~CReject(
void);
194 static LPHOOKFUNC m_GetFunc(
int iHookType)
198 case WH_MSGFILTER:
return WinHook::HookMSGFILTER;
199 case WH_JOURNALRECORD:
return WinHook::HookJOURNALRECORD;
200 case WH_JOURNALPLAYBACK:
return WinHook::HookJOURNALPLAYBACK;
201 case WH_KEYBOARD:
return WinHook::HookKEYBOARD;
202 case WH_GETMESSAGE:
return WinHook::HookGETMESSAGE;
203 case WH_CALLWNDPROC :
return WinHook::HookCALLWNDPROC;
204 case WH_CBT:
return WinHook::HookCBT;
205 case WH_SYSMSGFILTER:
return WinHook::HookSYSMSGFILTER;
206 case WH_MOUSE:
return WinHook::HookMOUSE;
207 case WH_HARDWARE:
return WinHook::HookHARDWARE;
208 case WH_DEBUG:
return WinHook::HookDEBUG;
209 case WH_SHELL:
return WinHook::HookSHELL;
210 case WH_FOREGROUNDIDLE:
return WinHook::HookFOREGROUNDIDLE;
211 case WH_CALLWNDPROCRET:
return WinHook::HookCALLWNDPROCRET;
212 case WH_KEYBOARD_LL:
return WinHook::HookKEYBOARD_LL;
213 case WH_MOUSE_LL:
return WinHook::HookMOUSE_LL;
239 case DLL_PROCESS_ATTACH:
240 WinHook::g_hInstance =
static_cast<HINSTANCE
>(hModule);
241 WinHook::g_dwThreadId = 0;
243 case DLL_PROCESS_DETACH:
246 case DLL_THREAD_ATTACH:
247 case DLL_THREAD_DETACH:
262 WinHook::g_hInstance = hInstance;
263 WinHook::g_dwThreadId = dwThreadId;
274 static HHOOK
Hook(
int iHookType, HOOKPROC PF)
276 static CReject s_cReje;
277 LPHOOKFUNC P = m_GetFunc(iHookType);
278 if ( P != NULL ){
return P(
true, PF); }
291 LPHOOKFUNC P = m_GetFunc(iHookType);
292 if ( P != NULL ){ P(
false, NULL); }
301 for (
int i = WH_MIN; i < 30; i++ )
311inline CWindowsHooker::CReject::~CReject(
void)
static bool Unhook(int iHookType)
[登録] フック解除
static HHOOK Hook(int iHookType, HOOKPROC PF)
[登録] フック登録
static void OnDllMain(HANDLE hModule, DWORD reason)
[設定] DllMain 時の処理 DLL のメイン関数がコールされた時にコールする関数です。 reason によって、処理を行います。
static void SetEnvironment(HINSTANCE hInstance, DWORD dwThreadId=0)
[設定] 環境登録
static void UnhookAll(void)
[登録] 全フックリスナー解除