aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/platform/MSWindowsHookResource.cpp
blob: ced5ff124e90bec6f437a01426b6094485f73c7e (plain) (blame)
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
#include "MSWindowsHookResource.h"

WindowsHookResource::WindowsHookResource() :
    _hook(NULL)
{
}

WindowsHookResource::~WindowsHookResource()
{
    unset();
}

bool WindowsHookResource::set(int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId)
{
    if (is_set())
        return false;
    _hook = SetWindowsHookEx(idHook, lpfn, hmod, dwThreadId);
    return is_set();
}

bool WindowsHookResource::unset()
{
    if (is_set()) {
        if (UnhookWindowsHookEx(_hook) == 0) {
            return false;
        }
        _hook = NULL;
    }
    return true;
}

bool WindowsHookResource::is_set() const { return _hook != NULL; }
WindowsHookResource::operator HHOOK() const { return _hook; }