@@ -58,9 +58,39 @@ namespace TranslucentFlyouts
58
58
constexpr UINT LDR_DLL_NOTIFICATION_REASON_LOADED{ 1 };
59
59
constexpr UINT LDR_DLL_NOTIFICATION_REASON_UNLOADED{ 2 };
60
60
61
- inline const auto g_actualLdrRegisterDllNotification{ reinterpret_cast <NTSTATUS (NTAPI*)(ULONG, HookHelper::PLDR_DLL_NOTIFICATION_FUNCTION, PVOID, PVOID*)>(GetProcAddress (GetModuleHandleW (L" ntdll.dll" ), " LdrRegisterDllNotification" )) };
62
- inline const auto g_actualLdrUnregisterDllNotification{ reinterpret_cast <NTSTATUS (NTAPI*)(PVOID)>(GetProcAddress (GetModuleHandleW (L" ntdll.dll" ), " LdrUnregisterDllNotification" )) };
61
+ __forceinline NTSTATUS NTAPI LdrRegisterDllNotification (
62
+ ULONG flags,
63
+ PLDR_DLL_NOTIFICATION_FUNCTION notificationFunction,
64
+ PVOID context,
65
+ PVOID* cookie
66
+ )
67
+ {
68
+ static const auto s_actualLdrRegisterDllNotification{ reinterpret_cast <NTSTATUS (NTAPI*)(ULONG, HookHelper::PLDR_DLL_NOTIFICATION_FUNCTION, PVOID, PVOID*)>(GetProcAddress (GetModuleHandleW (L" ntdll.dll" ), " LdrRegisterDllNotification" )) };
69
+ if (s_actualLdrRegisterDllNotification) [[likely]]
70
+ {
71
+ return s_actualLdrRegisterDllNotification (
72
+ flags,
73
+ notificationFunction,
74
+ context,
75
+ cookie
76
+ );
77
+ }
78
+
79
+ return 0xC000000F ;
80
+ }
81
+ __forceinline NTSTATUS NTAPI LdrUnregisterDllNotification (PVOID cookie)
82
+ {
83
+ static const auto s_actualLdrUnregisterDllNotification{ reinterpret_cast <NTSTATUS (NTAPI*)(PVOID)>(GetProcAddress (GetModuleHandleW (L" ntdll.dll" ), " LdrUnregisterDllNotification" )) };
84
+ if (s_actualLdrUnregisterDllNotification) [[likely]]
85
+ {
86
+ return s_actualLdrUnregisterDllNotification (
87
+ cookie
88
+ );
89
+ }
63
90
91
+ return 0xC000000F ;
92
+ }
93
+
64
94
void WriteMemory (PVOID memoryAddress, const std::function<void ()>&& callback);
65
95
PVOID InjectCallbackToThread (DWORD threadId, const std::function<void ()>& callback);
66
96
HMODULE GetProcessModule (HANDLE processHandle, std::wstring_view dllPath);
@@ -134,9 +164,21 @@ namespace TranslucentFlyouts
134
164
void Detach (PVOID* realFuncAddr, PVOID hookFuncAddr) noexcept (false );
135
165
}
136
166
137
- inline UINT TFM_REMOVESUBCLASS{ RegisterWindowMessageW (L" TranslucentFlyouts.RemoveWindowSublcass" ) };
138
- inline UINT TFM_ATTACH{ RegisterWindowMessageW (L" TranslucentFlyouts.Attach" ) };
139
- inline UINT TFM_DETACH{ RegisterWindowMessageW (L" TranslucentFlyouts.Detach" ) };
167
+ __forceinline UINT GetRemoveSubclassMsg ()
168
+ {
169
+ static UINT TFM_REMOVESUBCLASS{ RegisterWindowMessageW (L" TranslucentFlyouts.RemoveWindowSublcass" ) };
170
+ return TFM_REMOVESUBCLASS;
171
+ }
172
+ __forceinline UINT GetAttachMsg ()
173
+ {
174
+ static UINT TFM_ATTACH{ RegisterWindowMessageW (L" TranslucentFlyouts.Attach" ) };
175
+ return TFM_ATTACH;
176
+ }
177
+ __forceinline UINT GetDetachMsg ()
178
+ {
179
+ static UINT TFM_DETACH{ RegisterWindowMessageW (L" TranslucentFlyouts.Detach" ) };
180
+ return TFM_DETACH;
181
+ }
140
182
inline constexpr std::wstring_view subclassPropPrefix{ L" TranslucentFlyouts.Token" };
141
183
142
184
namespace HwndProp
@@ -198,7 +240,7 @@ namespace TranslucentFlyouts
198
240
if (SetWindowSubclass (hwnd, Storage<subclassProc>::Wrapper, 0 , 0 ))
199
241
{
200
242
windowList.push_back (hwnd);
201
- Storage<subclassProc>::Wrapper (hwnd, TFM_ATTACH , 0 , 0 , 0 , 0 );
243
+ Storage<subclassProc>::Wrapper (hwnd, GetAttachMsg () , 0 , 0 , 0 , 0 );
202
244
}
203
245
};
204
246
@@ -217,7 +259,7 @@ namespace TranslucentFlyouts
217
259
{
218
260
if (threadId == GetCurrentThreadId ())
219
261
{
220
- Storage<subclassProc>::Wrapper (hwnd, TFM_DETACH , windowDestroyed, 0 , 0 , 0 );
262
+ Storage<subclassProc>::Wrapper (hwnd, GetDetachMsg () , windowDestroyed, 0 , 0 , 0 );
221
263
if (RemoveWindowSubclass (hwnd, Storage<subclassProc>::Wrapper, 0 ))
222
264
{
223
265
windowList.erase (std::remove (windowList.begin (), windowList.end (), hwnd), windowList.end ());
@@ -226,7 +268,7 @@ namespace TranslucentFlyouts
226
268
}
227
269
else
228
270
{
229
- SendMessageW (hwnd, TFM_REMOVESUBCLASS , 0 , 0 );
271
+ SendMessageW (hwnd, GetRemoveSubclassMsg () , 0 , 0 );
230
272
}
231
273
}
232
274
}
@@ -250,7 +292,7 @@ namespace TranslucentFlyouts
250
292
DWORD_PTR dwRefData
251
293
)
252
294
{
253
- if (uMsg == TFM_REMOVESUBCLASS )
295
+ if (uMsg == GetRemoveSubclassMsg () )
254
296
{
255
297
Attach<subclassProc>(hWnd, false );
256
298
return 0 ;
@@ -294,12 +336,12 @@ namespace TranslucentFlyouts
294
336
if (value)
295
337
{
296
338
windowList.push_back (hwnd);
297
- Storage<subclassProc>::Wrapper (hwnd, TFM_ATTACH , windowDestroyed, 0 );
339
+ Storage<subclassProc>::Wrapper (hwnd, GetAttachMsg () , windowDestroyed, 0 );
298
340
}
299
341
}
300
342
if (!attach && refCount == 0 )
301
343
{
302
- Storage<subclassProc>::Wrapper (hwnd, TFM_DETACH , windowDestroyed, 0 );
344
+ Storage<subclassProc>::Wrapper (hwnd, GetDetachMsg () , windowDestroyed, 0 );
303
345
if (SetWindowLongPtrW (hwnd, GWLP_WNDPROC, HwndProp::Get<LONG_PTR>(hwnd, GetNamespace<subclassProc>(), propName)))
304
346
{
305
347
windowList.erase (std::remove (windowList.begin (), windowList.end (), hwnd), windowList.end ());
0 commit comments