1 |
astrand |
930 |
//********************************************************************************* |
2 |
|
|
// |
3 |
|
|
//Title: Terminal Services Window Clipper |
4 |
|
|
// |
5 |
|
|
//Author: Martin Wickett |
6 |
|
|
// |
7 |
|
|
//Date: 2004 |
8 |
|
|
// |
9 |
|
|
//********************************************************************************* |
10 |
|
|
|
11 |
|
|
#include "hook.h" |
12 |
|
|
|
13 |
astrand |
933 |
HINSTANCE WTSWinClipper::mCbtDllHinst = 0; |
14 |
|
|
SETHOOKS WTSWinClipper::mSetCbtHook = 0; |
15 |
|
|
REMOVEHOOKS WTSWinClipper::mRemoveCbtHook = 0; |
16 |
|
|
GETINSTANCECOUNT WTSWinClipper::mGetInstanceCount = 0; |
17 |
astrand |
930 |
|
18 |
|
|
bool WTSWinClipper::Init() |
19 |
|
|
{ |
20 |
astrand |
933 |
if (mCbtDllHinst) |
21 |
|
|
return true; |
22 |
astrand |
930 |
|
23 |
astrand |
933 |
while (true) { |
24 |
|
|
// try to load hookdll.dll |
25 |
|
|
if (!(mCbtDllHinst = LoadLibrary("hookdll.dll"))) |
26 |
|
|
break; |
27 |
astrand |
930 |
|
28 |
astrand |
933 |
// check number of instances |
29 |
|
|
if (! |
30 |
astrand |
937 |
(mGetInstanceCount = |
31 |
|
|
(GETINSTANCECOUNT) GetProcAddress(mCbtDllHinst, |
32 |
|
|
"GetInstanceCount"))) |
33 |
astrand |
933 |
break; |
34 |
astrand |
930 |
|
35 |
|
|
|
36 |
astrand |
933 |
// get our hook function |
37 |
|
|
if (! |
38 |
astrand |
937 |
(mSetCbtHook = |
39 |
|
|
(SETHOOKS) GetProcAddress(mCbtDllHinst, "SetCbtHook"))) |
40 |
astrand |
933 |
break; |
41 |
astrand |
930 |
|
42 |
astrand |
933 |
// get our unkook function |
43 |
|
|
if (! |
44 |
astrand |
937 |
(mRemoveCbtHook = |
45 |
|
|
(REMOVEHOOKS) GetProcAddress(mCbtDllHinst, "RemoveCbtHook"))) |
46 |
astrand |
933 |
break; |
47 |
astrand |
930 |
|
48 |
astrand |
933 |
// report success |
49 |
|
|
return true; |
50 |
|
|
} |
51 |
astrand |
930 |
|
52 |
astrand |
933 |
// if we got here something went wrong |
53 |
|
|
if (mCbtDllHinst) { |
54 |
|
|
FreeLibrary(mCbtDllHinst); |
55 |
|
|
mCbtDllHinst = 0; |
56 |
|
|
} |
57 |
astrand |
930 |
|
58 |
astrand |
933 |
return false; |
59 |
astrand |
930 |
} |