forked from nir9/lightwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm_dll.c
72 lines (58 loc) · 1.55 KB
/
wm_dll.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <Windows.h>
#include <stdio.h>
#include "targetver.h"
#include "messages.h"
#include "debug.h"
DWORD lightwmMainThreadId = 0;
void readAddress() {
// Open the shared memory region
HANDLE hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
"lightwmthreadid" // name of mapping object
);
if (hMapFile == NULL) {
DEBUG_PRINT("Could not open file mapping object (%lu).", GetLastError());
return;
}
LPVOID lpMapAddress = MapViewOfFile(
hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
sizeof(DWORD)
);
if (lpMapAddress == NULL) {
DEBUG_PRINT("Could not map view of file (%lu).", GetLastError());
CloseHandle(hMapFile);
return;
}
CopyMemory(&lightwmMainThreadId, (PVOID)lpMapAddress, sizeof(DWORD));
UnmapViewOfFile(lpMapAddress);
CloseHandle(hMapFile);
}
__declspec(dllexport) LRESULT CALLBACK ShellProc(int code, WPARAM wparam, LPARAM lparam) {
if (code == HSHELL_WINDOWCREATED || code == HSHELL_WINDOWDESTROYED) {
PostThreadMessageW(lightwmMainThreadId, LWM_WINDOW_EVENT, 0, 0);
}
return CallNextHookEx(NULL, code, wparam, lparam);
}
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD ulReasonForCall, LPVOID lpReserved)
{
switch(ulReasonForCall) {
case DLL_PROCESS_ATTACH:
DEBUG_PRINT("DLL Loaded");
readAddress();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
DEBUG_PRINT("DLL Freed");
break;
default:
break;
}
return TRUE;
}