-
Notifications
You must be signed in to change notification settings - Fork 6
/
HookFuncs.cpp
45 lines (39 loc) · 1.32 KB
/
HookFuncs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "resource.h"
#include "CommonFuncs.h"
HINSTANCE hookDll = NULL;
HHOOK hook = NULL;
void Hook_Start()
{
if (hook)
{
//Request other applications to update their options
UINT updateHookOptionsMsg = RegisterWindowMessage(WM_TE_UPDATEHOOKOPTIONS);
SendMessage(HWND_BROADCAST, updateHookOptionsMsg, 0,0);
}
else
{
//Set the hook
hookDll = LoadLibrary(_T("hook.dll"));
HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hookDll, "GetMessageProc@12");
hook = SetWindowsHookEx(WH_GETMESSAGE, hookProc, hookDll, 0);
if (!hook)
ErrorBox(NULL, FALSE, _T("Unable to set the hook. Error: %d"), GetLastError());
}
}
void Hook_Stop()
{
if (hook)
{
//Broadcast a "unhooked" message
UINT unhookMsg = RegisterWindowMessage(WM_TE_UNHOOKED);
SendMessage(HWND_BROADCAST, unhookMsg, 0,0);
/*DWORD recipients = BSM_APPLICATIONS;
BroadcastSystemMessage(BSF_FLUSHDISK|BSF_FORCEIFHUNG|BSF_IGNORECURRENTTASK, &recipients, unhookMsg, 0,0);*/
//Unset the hook
BOOL ret = UnhookWindowsHookEx(hook);
if (ret == FALSE)
ErrorBox(NULL, FALSE, _T("Unable to unset the hook. Error: %d"), GetLastError());
FreeLibrary(hookDll);
hook = NULL;
}
}