diff options
author | George Hazan <ghazan@miranda.im> | 2018-05-18 14:16:30 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-05-18 14:16:30 +0300 |
commit | 73d12d0f6eb5c673a951eec94ddf5cdeeacde369 (patch) | |
tree | efd476c9f8ba590f07a1fbfed85fa13e994a596f | |
parent | 0f6d791bb25af9b70637601ebe50029cb69b2e75 (diff) |
constructor of CMPlugin now registers it automatically in the module list, no need to call RegisterModule manually
-rw-r--r-- | include/delphi/m_core.inc | 12 | ||||
-rw-r--r-- | include/m_core.h | 6 | ||||
-rw-r--r-- | include/newpluginapi.h | 2 | ||||
-rw-r--r-- | libs/win32/mir_core.lib | bin | 322596 -> 322576 bytes | |||
-rw-r--r-- | libs/win64/mir_core.lib | bin | 323610 -> 323556 bytes | |||
-rw-r--r-- | src/mir_app/src/CMPluginBase.cpp | 3 | ||||
-rw-r--r-- | src/mir_app/src/newplugins.cpp | 7 | ||||
-rw-r--r-- | src/mir_app/src/proto_ui.cpp | 6 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 4 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 4 | ||||
-rw-r--r-- | src/mir_core/src/miranda.h | 7 | ||||
-rw-r--r-- | src/mir_core/src/modules.cpp | 38 | ||||
-rw-r--r-- | src/mir_core/src/threads.cpp | 9 |
13 files changed, 45 insertions, 53 deletions
diff --git a/include/delphi/m_core.inc b/include/delphi/m_core.inc index f5af2c3ca4..7e913e2d7a 100644 --- a/include/delphi/m_core.inc +++ b/include/delphi/m_core.inc @@ -382,18 +382,6 @@ function mir_wstrcmpi(const p1,p2:PWideChar):int; stdcall; external CoreDLL name 'mir_wstrcmpi';
///////////////////////////////////////////////////////////////////////////////
-// modules
-
-procedure RegisterModule(hInst:HINST); stdcall;
- external CoreDLL name 'RegisterModule';
-procedure UnregisterModule(hInst:HINST); stdcall;
- external CoreDLL name 'UnregisterModule';
-
-function GetInstByAddress(codePtr:pointer):HINST; stdcall;
- external CoreDLL name 'GetInstByAddress';
-
-
-///////////////////////////////////////////////////////////////////////////////
// print functions
function mir_snprintf(buffer:PAnsiChar;count:size_t;fmt:PAnsiChar{, ...}):int; stdcall;
diff --git a/include/m_core.h b/include/m_core.h index e5d7cbfb59..2b85a8e36c 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -309,10 +309,12 @@ MIR_CORE_DLL(wchar_t*) mir_wstrndup(const wchar_t *str, size_t len); ///////////////////////////////////////////////////////////////////////////////
// modules
-MIR_CORE_DLL(void) RegisterModule(HINSTANCE hInst);
-MIR_CORE_DLL(void) UnregisterModule(HINSTANCE hInst);
+class CMPluginBase;
+MIR_CORE_DLL(void) RegisterModule(CMPluginBase*);
+MIR_CORE_DLL(void) UnregisterModule(CMPluginBase*);
MIR_CORE_DLL(HINSTANCE) GetInstByAddress(void* codePtr);
+MIR_CORE_DLL(CMPluginBase&) GetPluginByInstance(HINSTANCE hInst);
///////////////////////////////////////////////////////////////////////////////
// print functions
diff --git a/include/newpluginapi.h b/include/newpluginapi.h index 278b9192e4..c7c8f37a42 100644 --- a/include/newpluginapi.h +++ b/include/newpluginapi.h @@ -157,9 +157,9 @@ class MIR_APP_EXPORT CMPluginBase void tryOpenLog();
protected:
+ HINSTANCE m_hInst;
const char *m_szModuleName;
HANDLE m_hLogger = nullptr;
- HINSTANCE m_hInst;
CMPluginBase(const char *moduleName);
~CMPluginBase();
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib Binary files differindex 390fa72fb2..92ef6949b1 100644 --- a/libs/win32/mir_core.lib +++ b/libs/win32/mir_core.lib diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib Binary files differindex 650496fdd4..5a162b096e 100644 --- a/libs/win64/mir_core.lib +++ b/libs/win64/mir_core.lib diff --git a/src/mir_app/src/CMPluginBase.cpp b/src/mir_app/src/CMPluginBase.cpp index e30fdb3320..72c7beb723 100644 --- a/src/mir_app/src/CMPluginBase.cpp +++ b/src/mir_app/src/CMPluginBase.cpp @@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. CMPluginBase::CMPluginBase(const char *moduleName) : m_szModuleName(moduleName) { + ::RegisterModule(this); } CMPluginBase::~CMPluginBase() @@ -35,6 +36,8 @@ CMPluginBase::~CMPluginBase() mir_closeLog(m_hLogger); m_hLogger = nullptr; } + + ::UnregisterModule(this); } void CMPluginBase::tryOpenLog() diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index fa83a8ec39..262d3adc30 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -332,7 +332,6 @@ void Plugin_Uninit(pluginEntry *p) // we need to kill all resources which belong to that DLL before calling FreeLibrary
KillModuleEventHooks(hInst);
KillModuleServices(hInst);
- UnregisterModule(hInst);
FreeLibrary(hInst);
memset(&p->bpi, 0, sizeof(p->bpi));
@@ -457,7 +456,6 @@ pluginEntry* OpenPlugin(wchar_t *tszFileName, wchar_t *dir, wchar_t *path) // copy the dblink stuff
p->bpi = bpi;
- RegisterModule(p->bpi.hInst);
if (bpi.Load() != 0)
p->bFailed = true;
else
@@ -563,7 +561,6 @@ bool TryLoadPlugin(pluginEntry *p, bool bDynamic) // contact list is loaded via clistlink, db - via DATABASELINK
// so we should call Load() only for usual plugins
if (!p->bLoaded && !p->bIsClist && !p->bIsDatabase) {
- RegisterModule(p->bpi.hInst);
if (p->bpi.Load() != 0)
return false;
@@ -641,7 +638,6 @@ static bool loadClistModule(wchar_t* exe, pluginEntry *p) ImageList_AddIcon_IconLibLoaded(hCListImages, SKINICON_OTHER_GROUPOPEN);
ImageList_AddIcon_IconLibLoaded(hCListImages, SKINICON_OTHER_GROUPSHUT);
- RegisterModule(p->bpi.hInst);
if (bpi.clistlink() == 0) {
p->bpi = bpi;
p->bLoaded = true;
@@ -698,7 +694,6 @@ int LaunchServicePlugin(pluginEntry *p) {
// plugin load failed - terminating Miranda
if (!p->bLoaded) {
- RegisterModule(p->bpi.hInst);
if (p->bpi.Load() != ERROR_SUCCESS) {
Plugin_Uninit(p);
return SERVICE_FAILED;
@@ -871,8 +866,6 @@ int LoadNewPluginsModuleInfos(void) mirandaVersion = Miranda_GetVersion();
- RegisterModule(g_hInst);
-
// remember where the mirandaboot.ini goes
PathToAbsoluteW(L"mirandaboot.ini", mirandabootini);
diff --git a/src/mir_app/src/proto_ui.cpp b/src/mir_app/src/proto_ui.cpp index 4740148f13..2658436bd1 100644 --- a/src/mir_app/src/proto_ui.cpp +++ b/src/mir_app/src/proto_ui.cpp @@ -23,14 +23,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
-HINSTANCE ProtoGetInstance(const char *szModuleName)
+CMPluginBase& ProtoGetInstance(const char *szModuleName)
{
PROTOACCOUNT *pa = Proto_GetAccount(szModuleName);
if (pa == nullptr)
- return nullptr;
+ return g_plugin;
MBaseProto *p = Proto_GetProto(pa->szProtoName);
- return (p == nullptr) ? nullptr : GetInstByAddress(p->fnInit);
+ return (p == nullptr) ? g_plugin : GetPluginByInstance(p->hInst);
}
/////////////////////////////////////////////////////////////////////////////////////////
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<HINSTANCE__> pluginListAddr;
+extern LIST<CMPluginBase> 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<HINSTANCE__> pluginListAddr(10, sttComparePlugins); +LIST<CMPluginBase> 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;
|