From 54d93d2c1ae60d2205476cc08ad356fc7bbd13e0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 8 Aug 2017 12:18:11 +0300 Subject: HookTemporaryEvent - new function that executes an event handler immediately if the event is missing usable to hook events that disappear after being used --- include/m_core.h | 4 ++++ libs/win32/mir_core.lib | Bin 317222 -> 317458 bytes libs/win64/mir_core.lib | Bin 318184 -> 318400 bytes src/mir_core/src/mir_core.def | 1 + src/mir_core/src/mir_core64.def | 1 + src/mir_core/src/modules.cpp | 24 ++++++++++++++++++++++++ 6 files changed, 30 insertions(+) diff --git a/include/m_core.h b/include/m_core.h index 6d31fe17bb..eba11f2956 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -109,6 +109,10 @@ MIR_CORE_DLL(HANDLE) HookEventParam(const char *name, MIRANDAHOOKPARAM hookProc MIR_CORE_DLL(HANDLE) HookEventObj(const char *name, MIRANDAHOOKOBJ hookProc, void* object); MIR_CORE_DLL(HANDLE) HookEventObjParam(const char *name, MIRANDAHOOKOBJPARAM hookProc, void* object, LPARAM lParam); MIR_CORE_DLL(HANDLE) HookEventMessage(const char *name, HWND hwnd, UINT message); + +// executes the event handler if event is missing +MIR_CORE_DLL(HANDLE) HookTemporaryEvent(const char *name, MIRANDAHOOK hookProc); + MIR_CORE_DLL(int) UnhookEvent(HANDLE hHook); MIR_CORE_DLL(void) KillObjectEventHooks(void* pObject); MIR_CORE_DLL(void) KillModuleEventHooks(HINSTANCE pModule); diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib index 4d146f0474..573e3e749a 100644 Binary files a/libs/win32/mir_core.lib and b/libs/win32/mir_core.lib differ diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib index 147ada0405..96c16192bd 100644 Binary files a/libs/win64/mir_core.lib and b/libs/win64/mir_core.lib differ diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index f5037de864..8a8e4df230 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1050,3 +1050,4 @@ CallFunctionSync @1170 ?Hide@CDlgBase@@QAEXXZ @1238 NONAME ?Resize@CDlgBase@@QAEXXZ @1239 NONAME Utils_IsRtl @1240 +HookTemporaryEvent @1241 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 31edd2dbea..f188b5b51d 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1050,3 +1050,4 @@ CallFunctionSync @1170 ?Hide@CDlgBase@@QEAAXXZ @1238 NONAME ?Resize@CDlgBase@@QEAAXXZ @1239 NONAME Utils_IsRtl @1240 +HookTemporaryEvent @1241 diff --git a/src/mir_core/src/modules.cpp b/src/mir_core/src/modules.cpp index c6908e723d..ae7cd45f1e 100644 --- a/src/mir_core/src/modules.cpp +++ b/src/mir_core/src/modules.cpp @@ -332,6 +332,30 @@ MIR_CORE_DLL(HANDLE) HookEventObjParam(const char *name, MIRANDAHOOKOBJPARAM hoo return HookEventInt(4, name, (MIRANDAHOOK)hookProc, object, lParam); } +MIR_CORE_DLL(HANDLE) HookTemporaryEvent(const char *name, MIRANDAHOOK hookProc) +{ + mir_cslockfull lck(csHooks); + + int idx; + if ((idx = hooks.getIndex((THook*)name)) == -1) { + lck.unlock(); + hookProc(0, 0); + return NULL; + } + + THook *p = hooks[idx]; + p->subscriber = (THookSubscriber*)mir_realloc(p->subscriber, sizeof(THookSubscriber)*(p->subscriberCount + 1)); + + THookSubscriber &s = p->subscriber[p->subscriberCount]; + memset(&s, 0, sizeof(THookSubscriber)); + s.type = 1; + s.pfnHook = hookProc; + s.hOwner = GetInstByAddress(hookProc); + + p->subscriberCount++; + return (HANDLE)((p->id << 16) | p->subscriberCount); +} + MIR_CORE_DLL(HANDLE) HookEventMessage(const char *name, HWND hwnd, UINT message) { mir_cslock lck(csHooks); -- cgit v1.2.3