From 73d12d0f6eb5c673a951eec94ddf5cdeeacde369 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 18 May 2018 14:16:30 +0300 Subject: constructor of CMPlugin now registers it automatically in the module list, no need to call RegisterModule manually --- src/mir_core/src/mir_core.def | 4 ++-- src/mir_core/src/mir_core64.def | 4 ++-- src/mir_core/src/miranda.h | 7 ++----- src/mir_core/src/modules.cpp | 38 ++++++++++++++++++++++---------------- src/mir_core/src/threads.cpp | 9 ++++++--- 5 files changed, 34 insertions(+), 28 deletions(-) (limited to 'src/mir_core') diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 2936dbf410..3940104584 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -497,7 +497,7 @@ mir_wstrcmpi @280 ??0CDbLink@@QAE@PBD0EK@Z @639 NONAME ??0CDbLink@@QAE@PBD0EPA_W@Z @640 NONAME ??0CDlgBase@@QAE@ABV0@@Z @641 NONAME -??0CDlgBase@@QAE@PAUHINSTANCE__@@H@Z @642 NONAME +??0CDlgBase@@QAE@AAVCMPluginBase@@H@Z @642 NONAME ??1CCtrlBase@@UAE@XZ @645 NONAME ??1CCtrlButton@@UAE@XZ @646 NONAME ??1CCtrlCheck@@UAE@XZ @647 NONAME @@ -516,7 +516,6 @@ mir_wstrcmpi @280 ??1CDlgBase@@UAE@XZ @660 NONAME ??4CDataLink@@QAEAAV0@ABV0@@Z @675 NONAME ??4CDbLink@@QAEAAV0@ABV0@@Z @676 NONAME -??4CDlgBase@@QAEAAV0@ABV0@@Z @677 NONAME ??_7CCtrlBase@@6B@ @679 NONAME ??_7CCtrlButton@@6B@ @680 NONAME ??_7CCtrlCheck@@6B@ @681 NONAME @@ -1069,3 +1068,4 @@ IsTerminalDisconnected @1245 CallObjectEventHook @1259 ?db_get_sm@@YG?AV?$CMStringT@DV?$ChTraitsCRT@D@@@@IPBD0@Z @1260 NONAME ?db_get_wsm@@YG?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@IPBD0@Z @1261 NONAME +GetPluginByInstance @1262 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index ed12967625..2b6d5d926c 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -497,7 +497,7 @@ mir_wstrcmpi @280 ??0CDbLink@@QEAA@PEBD0EK@Z @639 NONAME ??0CDbLink@@QEAA@PEBD0EPEA_W@Z @640 NONAME ??0CDlgBase@@QEAA@AEBV0@@Z @641 NONAME -??0CDlgBase@@QEAA@PEAUHINSTANCE__@@H@Z @642 NONAME +??0CDlgBase@@QEAA@AEAVCMPluginBase@@H@Z @642 NONAME ??1CCtrlBase@@UEAA@XZ @645 NONAME ??1CCtrlButton@@UEAA@XZ @646 NONAME ??1CCtrlCheck@@UEAA@XZ @647 NONAME @@ -516,7 +516,6 @@ mir_wstrcmpi @280 ??1CDlgBase@@UEAA@XZ @660 NONAME ??4CDataLink@@QEAAAEAV0@AEBV0@@Z @675 NONAME ??4CDbLink@@QEAAAEAV0@AEBV0@@Z @676 NONAME -??4CDlgBase@@QEAAAEAV0@AEBV0@@Z @677 NONAME ??_7CCtrlBase@@6B@ @679 NONAME ??_7CCtrlButton@@6B@ @680 NONAME ??_7CCtrlCheck@@6B@ @681 NONAME @@ -1069,3 +1068,4 @@ IsTerminalDisconnected @1245 CallObjectEventHook @1259 ?db_get_sm@@YA?AV?$CMStringT@DV?$ChTraitsCRT@D@@@@IPEBD0@Z @1260 NONAME ?db_get_wsm@@YA?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@IPEBD0@Z @1261 NONAME +GetPluginByInstance @1262 diff --git a/src/mir_core/src/miranda.h b/src/mir_core/src/miranda.h index cca2148589..f575399b0c 100644 --- a/src/mir_core/src/miranda.h +++ b/src/mir_core/src/miranda.h @@ -37,8 +37,6 @@ void DestroyModularEngine(void); int InitPathUtils(void); -HINSTANCE ProtoGetInstance(const char *szModuleName); - extern HINSTANCE g_hInst; extern HWND hAPCWindow; extern HANDLE hThreadQueueEmpty; @@ -83,13 +81,12 @@ struct THook CRITICAL_SECTION csHook; }; -extern LIST pluginListAddr; +extern LIST pluginListAddr; ///////////////////////////////////////////////////////////////////////////////////////// // langpack.cpp -char* LangPackTranslateString(MUUID* pUuid, const char *szEnglish, const int W); -wchar_t* LangPackTranslateStringT(int hLangpack, const wchar_t* tszEnglish); +char* LangPackTranslateString(MUUID* pUuid, const char *szEnglish, const int W); ///////////////////////////////////////////////////////////////////////////////////////// // threads.cpp diff --git a/src/mir_core/src/modules.cpp b/src/mir_core/src/modules.cpp index 707cf91523..086e584de9 100644 --- a/src/mir_core/src/modules.cpp +++ b/src/mir_core/src/modules.cpp @@ -695,24 +695,24 @@ static void DestroyServices() /////////////////////////////////////////////////////////////////////////////// -static int sttComparePlugins(const HINSTANCE__* p1, const HINSTANCE__* p2) +struct CMPlugin : public CMPluginBase { - if (p1 == p2) - return 0; - - return (p1 < p2) ? -1 : 1; -} + CMPlugin() : + CMPluginBase(nullptr) + {} +} g_plugin; -LIST pluginListAddr(10, sttComparePlugins); +LIST pluginListAddr(10, HandleKeySortT); -MIR_CORE_DLL(void) RegisterModule(HINSTANCE hInst) +MIR_CORE_DLL(void) RegisterModule(CMPluginBase *pPlugin) { - pluginListAddr.insert(hInst); + if (pPlugin->getInst() != nullptr) + pluginListAddr.insert(pPlugin); } -MIR_CORE_DLL(void) UnregisterModule(HINSTANCE hInst) +MIR_CORE_DLL(void) UnregisterModule(CMPluginBase *pPlugin) { - pluginListAddr.remove(hInst); + pluginListAddr.remove(pPlugin); } MIR_CORE_DLL(HINSTANCE) GetInstByAddress(void* codePtr) @@ -721,19 +721,25 @@ MIR_CORE_DLL(HINSTANCE) GetInstByAddress(void* codePtr) return nullptr; int idx; - List_GetIndex((SortedList*)&pluginListAddr, codePtr, &idx); + List_GetIndex((SortedList*)&pluginListAddr, (CMPluginBase*)&codePtr, &idx); if (idx > 0) idx--; - HINSTANCE result = pluginListAddr[idx]; + HINSTANCE result = pluginListAddr[idx]->getInst(); if (result < g_hInst && codePtr > g_hInst) - result = g_hInst; - else if (idx == 0 && codePtr < (void*)result) - result = nullptr; + return g_hInst; + if (idx == 0 && codePtr < (void*)result) + return nullptr; return result; } +MIR_CORE_DLL(CMPluginBase&) GetPluginByInstance(HINSTANCE hInst) +{ + CMPluginBase *pPlugin = pluginListAddr.find((CMPluginBase*)&hInst); + return (pPlugin == nullptr) ? g_plugin : *pPlugin; +} + /////////////////////////////////////////////////////////////////////////////// int InitialiseModularEngine(void) diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp index 0b564ecbd3..625b84781c 100644 --- a/src/mir_core/src/threads.cpp +++ b/src/mir_core/src/threads.cpp @@ -333,11 +333,14 @@ MIR_CORE_DLL(INT_PTR) Thread_Push(HINSTANCE hInst, void* pOwner) DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &p->hThread, 0, FALSE, DUPLICATE_SAME_ACCESS); p->dwThreadId = GetCurrentThreadId(); p->pObject = pOwner; - if (pluginListAddr.getIndex(hInst) != -1) + p->pEntryPoint = hInst; + + // try to find the precise match + CMPluginBase &pPlugin = GetPluginByInstance(hInst); + if (pPlugin.getInst() == hInst) p->hOwner = hInst; else - p->hOwner = GetInstByAddress((hInst != nullptr) ? (PVOID)hInst : GetCurrentThreadEntryPoint()); - p->pEntryPoint = hInst; + GetInstByAddress((hInst != nullptr) ? (PVOID)hInst : GetCurrentThreadEntryPoint()); threads.insert(p); return 0; -- cgit v1.2.3