summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/newpluginapi.h10
-rw-r--r--libs/win32/mir_app.libbin168864 -> 169616 bytes
-rw-r--r--libs/win64/mir_app.libbin164062 -> 164822 bytes
-rw-r--r--plugins/MirLua/src/environment.cpp2
-rw-r--r--plugins/MirLua/src/environment.h2
-rw-r--r--plugins/MirLua/src/mplugin.cpp6
-rw-r--r--plugins/MirLua/src/mplugin.h6
-rw-r--r--plugins/MirLua/src/script.cpp5
-rw-r--r--plugins/MirLua/src/script.h6
-rw-r--r--src/mir_app/src/CMPluginBase.cpp36
-rw-r--r--src/mir_app/src/dll_sniffer.cpp14
-rw-r--r--src/mir_app/src/mir_app.def3
-rw-r--r--src/mir_app/src/mir_app64.def3
-rw-r--r--src/mir_app/src/newplugins.cpp77
-rw-r--r--src/mir_app/src/pluginopts.cpp37
-rw-r--r--src/mir_app/src/plugins.h38
-rw-r--r--src/mir_core/src/miranda.h2
17 files changed, 146 insertions, 101 deletions
diff --git a/include/newpluginapi.h b/include/newpluginapi.h
index dfbadd3cb1..d4c8a4eac0 100644
--- a/include/newpluginapi.h
+++ b/include/newpluginapi.h
@@ -154,7 +154,10 @@ typedef struct PROTO_INTERFACE* (*pfnInitProto)(const char* szModuleName, const
// deallocates an account instance
typedef int(*pfnUninitProto)(PROTO_INTERFACE*);
-class MIR_APP_EXPORT CMPluginBase
+#pragma warning(push)
+#pragma warning(disable:4275)
+
+class MIR_APP_EXPORT CMPluginBase : public MNonCopyable
{
void tryOpenLog();
@@ -182,6 +185,9 @@ public:
__forceinline HINSTANCE getInst() const { return m_hInst; }
__forceinline void setInst(HINSTANCE hInst) { m_hInst = hInst; }
+ virtual int Load();
+ virtual int Unload();
+
////////////////////////////////////////////////////////////////////////////////////////
// registering module's resources
@@ -366,6 +372,8 @@ public:
}
};
+#pragma warning(pop)
+
extern struct CMPlugin g_plugin;
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib
index 171e8a9c3e..afeead3c61 100644
--- a/libs/win32/mir_app.lib
+++ b/libs/win32/mir_app.lib
Binary files differ
diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib
index d7b6692158..ac37cf3bdd 100644
--- a/libs/win64/mir_app.lib
+++ b/libs/win64/mir_app.lib
Binary files differ
diff --git a/plugins/MirLua/src/environment.cpp b/plugins/MirLua/src/environment.cpp
index 3127edee82..321eace843 100644
--- a/plugins/MirLua/src/environment.cpp
+++ b/plugins/MirLua/src/environment.cpp
@@ -138,7 +138,7 @@ void CMLuaEnvironment::CreateEnvironmentTable()
lua_setmetatable(L, -2);
}
-bool CMLuaEnvironment::Load()
+int CMLuaEnvironment::Load()
{
luaL_checktype(L, -1, LUA_TFUNCTION);
diff --git a/plugins/MirLua/src/environment.h b/plugins/MirLua/src/environment.h
index 1ede34756f..1c35c2073d 100644
--- a/plugins/MirLua/src/environment.h
+++ b/plugins/MirLua/src/environment.h
@@ -23,5 +23,5 @@ public:
HANDLE CreateServiceFunction(const char *name, int ref);
void DestroyServiceFunction(HANDLE hService);
- bool Load();
+ int Load() override;
};
diff --git a/plugins/MirLua/src/mplugin.cpp b/plugins/MirLua/src/mplugin.cpp
index 5262499e98..44e73ae9cc 100644
--- a/plugins/MirLua/src/mplugin.cpp
+++ b/plugins/MirLua/src/mplugin.cpp
@@ -24,7 +24,7 @@ CMPlugin::~CMPlugin()
Unload();
}
-void CMPlugin::Load()
+int CMPlugin::Load()
{
Log("Loading lua engine");
L = luaL_newstate();
@@ -36,9 +36,10 @@ void CMPlugin::Load()
CMLuaFunctionLoader::Load(L);
CMLuaModuleLoader::Load(L);
CMLuaScriptLoader::Load(L);
+ return 0;
}
-void CMPlugin::Unload()
+int CMPlugin::Unload()
{
Log("Unloading lua engine");
@@ -53,6 +54,7 @@ void CMPlugin::Unload()
KillObjectServices(L);
lua_close(L);
+ return 0;
}
void CMPlugin::Reload()
diff --git a/plugins/MirLua/src/mplugin.h b/plugins/MirLua/src/mplugin.h
index 9db92580f8..f448d06daf 100644
--- a/plugins/MirLua/src/mplugin.h
+++ b/plugins/MirLua/src/mplugin.h
@@ -8,8 +8,6 @@ struct CMPlugin : public PLUGIN<CMPlugin>
private:
lua_State *L;
- void Unload();
-
INT_PTR __cdecl Eval(WPARAM, LPARAM);
INT_PTR __cdecl Call(WPARAM, LPARAM);
INT_PTR __cdecl Exec(WPARAM, LPARAM);
@@ -20,7 +18,9 @@ public:
CMPlugin();
~CMPlugin();
- void Load();
+ int Load() override;
+ int Unload() override;
+
void Reload();
};
diff --git a/plugins/MirLua/src/script.cpp b/plugins/MirLua/src/script.cpp
index 0b6b148536..50e061b59c 100644
--- a/plugins/MirLua/src/script.cpp
+++ b/plugins/MirLua/src/script.cpp
@@ -62,7 +62,7 @@ CMLuaScript::Status CMLuaScript::GetStatus() const
return status;
}
-bool CMLuaScript::Load()
+int CMLuaScript::Load()
{
status = Failed;
@@ -114,7 +114,7 @@ bool CMLuaScript::Load()
return true;
}
-void CMLuaScript::Unload()
+int CMLuaScript::Unload()
{
if (status == Loaded) {
lua_rawgeti(L, LUA_REGISTRYINDEX, unloadRef);
@@ -129,6 +129,7 @@ void CMLuaScript::Unload()
lua_pushnil(L);
lua_setfield(L, -2, m_szModuleName);
lua_pop(L, 1);
+ return 0;
}
bool CMLuaScript::Reload()
diff --git a/plugins/MirLua/src/script.h b/plugins/MirLua/src/script.h
index 8ff5b40600..2caf88c925 100644
--- a/plugins/MirLua/src/script.h
+++ b/plugins/MirLua/src/script.h
@@ -17,8 +17,6 @@ private:
const wchar_t *fileName;
wchar_t filePath[MAX_PATH];
- void Unload();
-
public:
CMLuaScript(lua_State *L, const wchar_t *path);
CMLuaScript(const CMLuaScript &script);
@@ -33,6 +31,8 @@ public:
Status GetStatus() const;
- bool Load();
+ int Load() override;
+ int Unload() override;
+
bool Reload();
};
diff --git a/src/mir_app/src/CMPluginBase.cpp b/src/mir_app/src/CMPluginBase.cpp
index 91f3e952c8..397031fa9c 100644
--- a/src/mir_app/src/CMPluginBase.cpp
+++ b/src/mir_app/src/CMPluginBase.cpp
@@ -26,20 +26,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "plugins.h"
static int sttFakeID = -100;
-static LIST<CMPluginBase> pluginListAddr(10, HandleKeySortT);
+
+static int Compare(const CMPluginBase *p1, const CMPluginBase *p2)
+{
+ return INT_PTR(p1->getInst()) - INT_PTR(p2->getInst());
+}
+
+static LIST<CMPluginBase> pluginListAddr(10, Compare);
void RegisterModule(CMPluginBase *pPlugin)
{
pluginListAddr.insert(pPlugin);
}
-MIR_APP_DLL(HINSTANCE) GetInstByAddress(void* codePtr)
+MIR_APP_DLL(HINSTANCE) GetInstByAddress(void *codePtr)
{
if (pluginListAddr.getCount() == 0)
return nullptr;
int idx;
- List_GetIndex((SortedList*)&pluginListAddr, (CMPluginBase*)&codePtr, &idx);
+ void *boo[2] = { 0, codePtr };
+ List_GetIndex((SortedList*)&pluginListAddr, (CMPluginBase*)&boo, &idx);
if (idx > 0)
idx--;
@@ -85,19 +92,22 @@ MIR_APP_DLL(int) IsPluginLoaded(const MUUID &uuid)
char* GetPluginNameByInstance(HINSTANCE hInst)
{
- CMPluginBase *pPlugin = pluginListAddr.find((CMPluginBase*)&hInst);
+ HINSTANCE boo[2] = { 0, hInst };
+ CMPluginBase *pPlugin = pluginListAddr.find((CMPluginBase*)&boo);
return (pPlugin == nullptr) ? nullptr : pPlugin->getInfo().shortName;
}
MIR_APP_DLL(CMPluginBase&) GetPluginByInstance(HINSTANCE hInst)
{
- CMPluginBase *pPlugin = pluginListAddr.find((CMPluginBase*)&hInst);
+ HINSTANCE boo[2] = { 0, hInst };
+ CMPluginBase *pPlugin = pluginListAddr.find((CMPluginBase*)&boo);
return (pPlugin == nullptr) ? g_plugin : *pPlugin;
}
MIR_APP_DLL(int) GetPluginLangByInstance(HINSTANCE hInst)
{
- CMPluginBase *pPlugin = pluginListAddr.find((CMPluginBase*)&hInst);
+ HINSTANCE boo[2] = { 0, hInst };
+ CMPluginBase *pPlugin = pluginListAddr.find((CMPluginBase*)&boo);
return (pPlugin == nullptr) ? 0 : pPlugin->m_hLang;
}
@@ -139,6 +149,20 @@ CMPluginBase::~CMPluginBase()
pluginListAddr.remove(this);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int CMPluginBase::Load()
+{
+ return 0;
+}
+
+int CMPluginBase::Unload()
+{
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CMPluginBase::tryOpenLog()
{
wchar_t path[MAX_PATH];
diff --git a/src/mir_app/src/dll_sniffer.cpp b/src/mir_app/src/dll_sniffer.cpp
index c2a61d2e3b..1d8f928e74 100644
--- a/src/mir_app/src/dll_sniffer.cpp
+++ b/src/mir_app/src/dll_sniffer.cpp
@@ -56,7 +56,7 @@ __forceinline bool Contains(PIMAGE_SECTION_HEADER pISH, DWORD address, DWORD siz
return (address >= pISH->VirtualAddress && address + size <= pISH->VirtualAddress + pISH->SizeOfRawData);
}
-MUUID* GetPluginInterfaces(const wchar_t* ptszFileName, bool& bIsPlugin)
+MUUID* GetPluginInterfaces(const wchar_t *ptszFileName, bool &bIsPlugin)
{
int nChecks = 0;
bIsPlugin = false;
@@ -65,8 +65,8 @@ MUUID* GetPluginInterfaces(const wchar_t* ptszFileName, bool& bIsPlugin)
if (hFile == INVALID_HANDLE_VALUE)
return nullptr;
- MUUID* pResult = nullptr;
- BYTE* ptr = nullptr;
+ MUUID *pResult = nullptr;
+ BYTE *ptr = nullptr;
HANDLE hMap = CreateFileMapping(hFile, nullptr, PAGE_READONLY, 0, 0, nullptr);
__try {
@@ -143,7 +143,7 @@ MUUID* GetPluginInterfaces(const wchar_t* ptszFileName, bool& bIsPlugin)
WORD *ptrOrdRVA = (WORD*)&pSecStart[pED->AddressOfNameOrdinals];
DWORD *ptrFuncList = (DWORD*)&pSecStart[pED->AddressOfFunctions];
- MUUID* pIds = nullptr;
+ MUUID *pIds = nullptr;
bool bHasLoad = false, bHasUnload = false, bHasMuuids = false;
for (size_t i = 0; i < pED->NumberOfNames; i++, ptrRVA++, ptrOrdRVA++) {
char *szName = (char*)&pSecStart[*ptrRVA];
@@ -165,7 +165,7 @@ MUUID* GetPluginInterfaces(const wchar_t* ptszFileName, bool& bIsPlugin)
// a plugin might have no interfaces
if (bHasMuuids) {
int nLength = 1; // one for MIID_LAST
- for (MUUID* p = pIds; *p != miid_last; p++)
+ for (MUUID *p = pIds; *p != miid_last; p++)
nLength++;
pResult = (MUUID*)mir_alloc(sizeof(MUUID)*nLength);
@@ -189,8 +189,8 @@ MUUID* GetPluginInterfaces(const wchar_t* ptszFileName, bool& bIsPlugin)
VerQueryValue(&pSecStart[dwVersion], L"\\", (PVOID*)&vsffi, &blockSize);
UINT v[4] = { MIRANDA_VERSION_COREVERSION };
- if (MAKELONG(v[1], v[0]) == vsffi->dwProductVersionMS && MAKELONG(v[3], v[2]) == vsffi->dwProductVersionLS)
- nChecks++;
+ if (MAKELONG(v[1], v[0]) == (int)vsffi->dwProductVersionMS && MAKELONG(v[3], v[2]) == (int)vsffi->dwProductVersionLS)
+ nChecks++;
}
}
}
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index ba888977a6..6920cdcb3d 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -614,3 +614,6 @@ UnregisterPlugin @633
?addTTB@CMPluginBase@@QAEPAXPBUTTBButton@@@Z @643 NONAME
?g_clistApi@@3UCLIST_INTERFACE@@A @644 NONAME
?g_chatApi@@3UCHAT_MANAGER@@A @645 NONAME
+??_7CMPluginBase@@6B@ @646 NONAME
+?Load@CMPluginBase@@UAEHXZ @647 NONAME
+?Unload@CMPluginBase@@UAEHXZ @648 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 4631a91664..d72137f7cc 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -614,3 +614,6 @@ UnregisterPlugin @633
?addTTB@CMPluginBase@@QEAAPEAXPEBUTTBButton@@@Z @643 NONAME
?g_clistApi@@3UCLIST_INTERFACE@@A @644 NONAME
?g_chatApi@@3UCHAT_MANAGER@@A @645 NONAME
+??_7CMPluginBase@@6B@ @646 NONAME
+?Load@CMPluginBase@@UEAAHXZ @647 NONAME
+?Unload@CMPluginBase@@UEAAHXZ @648 NONAME
diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp
index 6c442e3bd5..7fda7cbbd5 100644
--- a/src/mir_app/src/newplugins.cpp
+++ b/src/mir_app/src/newplugins.cpp
@@ -202,26 +202,27 @@ static int checkPI(BASIC_PLUGIN_INFO *bpi, const PLUGININFOEX *pi)
return TRUE;
}
-int checkAPI(wchar_t* plugin, BASIC_PLUGIN_INFO* bpi, int checkTypeAPI)
+bool checkAPI(wchar_t *plugin, BASIC_PLUGIN_INFO *bpi, int checkTypeAPI)
{
SetErrorMode(SEM_FAILCRITICALERRORS); // disable error messages
HINSTANCE h = LoadLibrary(plugin);
SetErrorMode(0); // reset the system default
if (h == nullptr)
- return 0;
+ return false;
// loaded, check for exports
CMPluginBase &pPlugin = GetPluginByInstance(h);
- bpi->Load = (Miranda_Plugin_Load)GetProcAddress(h, "Load");
- bpi->Unload = (Miranda_Plugin_Unload)GetProcAddress(h, "Unload");
+ bpi->pfnLoad = (Miranda_Plugin_Load)GetProcAddress(h, "Load");
+ bpi->pfnUnload = (Miranda_Plugin_Unload)GetProcAddress(h, "Unload");
- // Load & Unload shall be defined anyway, and a dll must register itself during LoadLibrary
- if (!bpi->Load || !bpi->Unload || pPlugin.getInst() != h) {
+ // dll must register itself during LoadLibrary
+ if (pPlugin.getInst() != h) {
LBL_Error:
FreeLibrary(h);
- return 0;
+ return false;
}
+ bpi->pPlugin = &pPlugin;
bpi->Interfaces = (MUUID*)GetProcAddress(h, "MirandaInterfaces");
if (bpi->Interfaces == nullptr) {
// MirandaPluginInterfaces function is actual only for the only plugin, HistoryPlusPlus
@@ -236,18 +237,15 @@ LBL_Error:
if (!checkPI(bpi, &pi))
goto LBL_Error;
- bpi->pluginInfo = &pi;
// basic API is present
- if (checkTypeAPI == CHECKAPI_NONE) {
-LBL_Ok:
- bpi->hInst = h;
- return 1;
- }
- // check clist ?
+ if (checkTypeAPI == CHECKAPI_NONE)
+ return true;
+
+ // check clist?
if (checkTypeAPI == CHECKAPI_CLIST) {
bpi->clistlink = (CList_Initialise)GetProcAddress(h, "CListInitialise");
if ((pi.flags & UNICODE_AWARE) && bpi->clistlink)
- goto LBL_Ok;
+ return true;
}
goto LBL_Error;
}
@@ -257,13 +255,17 @@ void Plugin_Uninit(pluginEntry *p)
{
// if the basic API check had passed, call Unload if Load(void) was ever called
if (p->bLoaded) {
- p->bpi.Unload();
+ if (p->bpi.pfnUnload)
+ p->bpi.pfnUnload();
+ else
+ p->bpi.pPlugin->Unload();
p->bLoaded = false;
}
// release the library
- HINSTANCE hInst = p->bpi.hInst;
- if (hInst != nullptr) {
+ if (p->bpi.pPlugin != nullptr) {
+ HINSTANCE hInst = p->bpi.pPlugin->getInst();
+
// we need to kill all resources which belong to that DLL before calling FreeLibrary
KillModuleEventHooks(hInst);
KillModuleServices(hInst);
@@ -284,21 +286,22 @@ bool Plugin_UnloadDyn(pluginEntry *p)
if (p == nullptr)
return true;
- if (p->bpi.hInst) {
- if (CallPluginEventHook(p->bpi.hInst, hOkToExitEvent, 0, 0) != 0)
+ CMPluginBase *ppb = p->bpi.pPlugin;
+ if (HINSTANCE hInst = ppb->getInst()) {
+ if (CallPluginEventHook(hInst, hOkToExitEvent, 0, 0) != 0)
return false;
- KillModuleAccounts(p->bpi.hInst);
- KillModuleSubclassing(p->bpi.hInst);
+ KillModuleAccounts(hInst);
+ KillModuleSubclassing(hInst);
- CallPluginEventHook(p->bpi.hInst, hPreShutdownEvent, 0, 0);
- CallPluginEventHook(p->bpi.hInst, hShutdownEvent, 0, 0);
+ CallPluginEventHook(hInst, hPreShutdownEvent, 0, 0);
+ CallPluginEventHook(hInst, hShutdownEvent, 0, 0);
- KillModuleEventHooks(p->bpi.hInst);
- KillModuleServices(p->bpi.hInst);
+ KillModuleEventHooks(hInst);
+ KillModuleServices(hInst);
}
- int _hLang = GetPluginLangByInstance(p->bpi.hInst);
+ int _hLang = ppb->m_hLang;
if (_hLang != 0) {
KillModuleMenus(_hLang);
KillModuleFonts(_hLang);
@@ -313,7 +316,7 @@ bool Plugin_UnloadDyn(pluginEntry *p)
KillModuleOptions(_hLang);
}
- NotifyFastHook(hevUnloadModule, (WPARAM)p->bpi.pluginInfo, (LPARAM)p->bpi.hInst);
+ NotifyFastHook(hevUnloadModule, (WPARAM)&ppb->getInfo(), (LPARAM)ppb->getInst());
// mark default plugins to be loaded
if (!p->bIsCore)
@@ -392,7 +395,7 @@ pluginEntry* OpenPlugin(wchar_t *tszFileName, wchar_t *dir, wchar_t *path)
// copy the dblink stuff
p->bpi = bpi;
- if (bpi.Load() != 0)
+ if (bpi.pfnLoad() != 0)
p->bFailed = true;
else
p->bLoaded = true;
@@ -463,7 +466,7 @@ bool TryLoadPlugin(pluginEntry *p, bool bDynamic)
if (!bDynamic && !isPluginOnWhiteList(p->pluginname))
return false;
- if (p->bpi.hInst == nullptr) {
+ if (p->bpi.pPlugin == nullptr) {
if (!p->bHasBasicApi) {
wchar_t exe[MAX_PATH], tszFullPath[MAX_PATH];
GetModuleFileName(nullptr, exe, _countof(exe));
@@ -503,7 +506,7 @@ 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) {
- if (p->bpi.Load() != 0)
+ if (p->bpi.pfnLoad() != 0)
return false;
p->bLoaded = true;
@@ -547,11 +550,12 @@ LBL_Error:
if (!TryLoadPlugin(pPlug, true))
goto LBL_Error;
+ CMPluginBase *ppb = pPlug->bpi.pPlugin;
if (bModulesLoadedFired) {
- if (CallPluginEventHook(pPlug->bpi.hInst, hModulesLoadedEvent, 0, 0) != 0)
+ if (CallPluginEventHook(ppb->getInst(), hModulesLoadedEvent, 0, 0) != 0)
goto LBL_Error;
- NotifyEventHooks(hevLoadModule, (WPARAM)pPlug->bpi.pluginInfo, (LPARAM)pPlug->bpi.hInst);
+ NotifyEventHooks(hevLoadModule, (WPARAM)&ppb->getInfo(), (LPARAM)ppb->getInst());
}
mr.pImpl = pPlug;
return true;
@@ -620,7 +624,7 @@ int UnloadPlugin(wchar_t* buf, int bufLen)
{
for (auto &it : pluginList.rev_iter()) {
if (!mir_wstrcmpi(it->pluginname, buf)) {
- GetModuleFileName(it->bpi.hInst, buf, bufLen);
+ GetModuleFileName(it->bpi.pPlugin->getInst(), buf, bufLen);
Plugin_Uninit(it);
return TRUE;
}
@@ -636,7 +640,8 @@ int LaunchServicePlugin(pluginEntry *p)
{
// plugin load failed - terminating Miranda
if (!p->bLoaded) {
- if (p->bpi.Load() != ERROR_SUCCESS) {
+ int res = (p->bpi.pfnLoad == 0) ? p->bpi.pPlugin->Load() : p->bpi.pfnLoad();
+ if (res != ERROR_SUCCESS) {
Plugin_Uninit(p);
return SERVICE_FAILED;
}
@@ -712,7 +717,7 @@ int LoadProtocolPlugins(void)
/* now loop thru and load all the other plugins, do this in one pass */
for (int i = 0; i < pluginList.getCount(); i++) {
pluginEntry *p = pluginList[i];
- if (!p->bIsProtocol || p->bpi.hInst != nullptr)
+ if (!p->bIsProtocol || p->bpi.pPlugin != nullptr)
continue;
wchar_t tszFullPath[MAX_PATH];
diff --git a/src/mir_app/src/pluginopts.cpp b/src/mir_app/src/pluginopts.cpp
index 8a60b5c56e..a94b9ffdcd 100644
--- a/src/mir_app/src/pluginopts.cpp
+++ b/src/mir_app/src/pluginopts.cpp
@@ -78,7 +78,7 @@ static BOOL dialogListPlugins(WIN32_FIND_DATA *fd, wchar_t *path, WPARAM, LPARAM
PluginListItemData *dat = (PluginListItemData*)mir_alloc(sizeof(PluginListItemData));
dat->hInst = hInst;
- dat->flags = pi.pluginInfo->flags;
+ dat->flags = pi.pPlugin->getInfo().flags;
dat->stdPlugin = 0;
if (pi.Interfaces) {
@@ -119,16 +119,17 @@ static BOOL dialogListPlugins(WIN32_FIND_DATA *fd, wchar_t *path, WPARAM, LPARAM
it.pszText = fd->cFileName;
ListView_SetItem(hwndList, &it);
- dat->author = sttUtf8auto(pi.pluginInfo->author);
- dat->copyright = sttUtf8auto(pi.pluginInfo->copyright);
- dat->description = sttUtf8auto(pi.pluginInfo->description);
- dat->homepage = sttUtf8auto(pi.pluginInfo->homepage);
- if (pi.pluginInfo->cbSize == sizeof(PLUGININFOEX))
- dat->uuid = pi.pluginInfo->uuid;
+ const PLUGININFOEX &ppi = pi.pPlugin->getInfo();
+ dat->author = sttUtf8auto(ppi.author);
+ dat->copyright = sttUtf8auto(ppi.copyright);
+ dat->description = sttUtf8auto(ppi.description);
+ dat->homepage = sttUtf8auto(ppi.homepage);
+ if (ppi.cbSize == sizeof(PLUGININFOEX))
+ dat->uuid = ppi.uuid;
else
memset(&dat->uuid, 0, sizeof(dat->uuid));
- wchar_t *shortNameT = mir_a2u(pi.pluginInfo->shortName);
+ wchar_t *shortNameT = mir_a2u(ppi.shortName);
// column 3: plugin short name
if (shortNameT) {
ListView_SetItemText(hwndList, iRow, 2, shortNameT);
@@ -146,17 +147,14 @@ static BOOL dialogListPlugins(WIN32_FIND_DATA *fd, wchar_t *path, WPARAM, LPARAM
mir_snwprintf(buf, L"%d.%d.%d.%d", HIWORD(fi->dwFileVersionMS), LOWORD(fi->dwFileVersionMS), HIWORD(fi->dwFileVersionLS), LOWORD(fi->dwFileVersionLS));
mir_free(pVerInfo);
}
- else
- mir_snwprintf(buf, L"%d.%d.%d.%d", HIBYTE(HIWORD(pi.pluginInfo->version)),
- LOBYTE(HIWORD(pi.pluginInfo->version)), HIBYTE(LOWORD(pi.pluginInfo->version)),
- LOBYTE(LOWORD(pi.pluginInfo->version)));
+ else mir_snwprintf(buf, L"%d.%d.%d.%d", HIBYTE(HIWORD(ppi.version)), LOBYTE(HIWORD(ppi.version)), HIBYTE(LOWORD(ppi.version)), LOBYTE(LOWORD(ppi.version)));
ListView_SetItemText(hwndList, iRow, 3, buf);
arPluginList.insert(dat);
}
- else
- mir_free(dat);
- FreeLibrary(pi.hInst);
+ else mir_free(dat);
+
+ FreeLibrary(pi.pPlugin->getInst());
return TRUE;
}
@@ -186,12 +184,13 @@ static bool LoadPluginDynamically(PluginListItemData *dat)
if (!TryLoadPlugin(pPlug, true))
goto LBL_Error;
- if (CallPluginEventHook(pPlug->bpi.hInst, hModulesLoadedEvent, 0, 0) != 0)
+ CMPluginBase *ppb = pPlug->bpi.pPlugin;
+ if (CallPluginEventHook(ppb->getInst(), hModulesLoadedEvent, 0, 0) != 0)
goto LBL_Error;
// if dynamically loaded plugin contains protocols, initialize the corresponding accounts
for (auto &pd : g_arProtos) {
- if (pd->hInst != pPlug->bpi.hInst)
+ if (pd->hInst != ppb->getInst())
continue;
for (auto &pa : accounts) {
@@ -205,8 +204,8 @@ static bool LoadPluginDynamically(PluginListItemData *dat)
}
}
- dat->hInst = pPlug->bpi.hInst;
- NotifyFastHook(hevLoadModule, (WPARAM)pPlug->bpi.pluginInfo, (LPARAM)pPlug->bpi.hInst);
+ dat->hInst = ppb->getInst();
+ NotifyFastHook(hevLoadModule, (WPARAM)&ppb->getInfo(), (LPARAM)ppb->getInst());
return true;
}
diff --git a/src/mir_app/src/plugins.h b/src/mir_app/src/plugins.h
index 5852865f8d..c837cb1a16 100644
--- a/src/mir_app/src/plugins.h
+++ b/src/mir_app/src/plugins.h
@@ -9,27 +9,27 @@
#define DEFMOD_REMOVED_PROTOCOLNETLIB 22
// basic export prototypes
-typedef int (__cdecl * Miranda_Plugin_Load) (void);
-typedef int (__cdecl * Miranda_Plugin_Unload) (void);
+typedef int(__cdecl *Miranda_Plugin_Load) (void);
+typedef int(__cdecl *Miranda_Plugin_Unload) (void);
// prototype for clists
-typedef int (__cdecl * CList_Initialise) (void);
+typedef int(__cdecl *CList_Initialise) (void);
// can all be nullptr
struct BASIC_PLUGIN_INFO
{
- HINSTANCE hInst;
- Miranda_Plugin_Load Load;
- Miranda_Plugin_Unload Unload;
- CList_Initialise clistlink;
- const PLUGININFOEX *pluginInfo; // must be freed if hInst == nullptr then its a copy
- MUUID *Interfaces; // array of supported interfaces
+ Miranda_Plugin_Load pfnLoad;
+ Miranda_Plugin_Unload pfnUnload;
+ CList_Initialise clistlink;
+ CMPluginBase* pPlugin;
+ MUUID* Interfaces; // array of supported interfaces
};
struct pluginEntry
{
wchar_t pluginname[64];
- struct {
+ struct
+ {
bool bFailed : 1; // not a valid plugin, or API is invalid, pluginname is valid
bool bOk : 1; // plugin should be loaded, if DB means nothing
bool bLoaded : 1; // Load(void) has been called, Unload() should be called.
@@ -45,7 +45,7 @@ struct pluginEntry
bool bIsClist : 1; // a CList implementation
bool bIsCrypto : 1; // crypto provider
};
-
+
BASIC_PLUGIN_INFO bpi;
};
@@ -56,13 +56,13 @@ int PluginOptionsInit(WPARAM, LPARAM);
void LoadPluginOptions();
void UnloadPluginOptions();
-int isPluginOnWhiteList(const wchar_t* pluginname);
-void SetPluginOnWhiteList(const wchar_t* pluginname, int allow);
+int isPluginOnWhiteList(const wchar_t *pluginname);
+void SetPluginOnWhiteList(const wchar_t *pluginname, int allow);
-int getDefaultPluginIdx(const MUUID& muuid);
+int getDefaultPluginIdx(const MUUID &muuid);
bool hasMuuid(const BASIC_PLUGIN_INFO&, const MUUID&);
-bool hasMuuid(const MUUID* pFirst, const MUUID&);
-int checkAPI(wchar_t* plugin, BASIC_PLUGIN_INFO* bpi, int checkTypeAPI);
+bool hasMuuid(const MUUID *pFirst, const MUUID&);
+bool checkAPI(wchar_t *plugin, BASIC_PLUGIN_INFO *bpi, int checkTypeAPI);
pluginEntry* OpenPlugin(wchar_t *tszFileName, wchar_t *dir, wchar_t *path);
@@ -70,7 +70,7 @@ bool TryLoadPlugin(pluginEntry *p, bool bDynamic);
void Plugin_Uninit(pluginEntry *p);
bool Plugin_UnloadDyn(pluginEntry *p);
-typedef BOOL (*SCAN_PLUGINS_CALLBACK) (WIN32_FIND_DATA * fd, wchar_t *path, WPARAM wParam, LPARAM lParam);
+typedef BOOL (*SCAN_PLUGINS_CALLBACK) (WIN32_FIND_DATA *fd, wchar_t *path, WPARAM wParam, LPARAM lParam);
void enumPlugins(SCAN_PLUGINS_CALLBACK cb, WPARAM wParam, LPARAM lParam);
struct MuuidReplacement
@@ -80,6 +80,6 @@ struct MuuidReplacement
pluginEntry* pImpl; // replacement plugin
};
-bool LoadCorePlugin( MuuidReplacement& );
+bool LoadCorePlugin(MuuidReplacement&);
-MUUID* GetPluginInterfaces(const wchar_t* ptszFileName, bool& bIsPlugin);
+MUUID* GetPluginInterfaces(const wchar_t *ptszFileName, bool &bIsPlugin);
diff --git a/src/mir_core/src/miranda.h b/src/mir_core/src/miranda.h
index 4757644250..ceaa486314 100644
--- a/src/mir_core/src/miranda.h
+++ b/src/mir_core/src/miranda.h
@@ -86,7 +86,7 @@ extern LIST<CMPluginBase> pluginListAddr;
/////////////////////////////////////////////////////////////////////////////////////////
// langpack.cpp
-char* LangPackTranslateString(MUUID* pUuid, const char *szEnglish, const int W);
+char* LangPackTranslateString(MUUID *pUuid, const char *szEnglish, const int W);
/////////////////////////////////////////////////////////////////////////////////////////
// threads.cpp