From b172c4bbc75cdad0e8ccd22292aa671ba43cac45 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 18 Apr 2018 18:14:33 +0300 Subject: PLUGIN<> to half-automatically calculate the dll's g_hInstance and pass it inside --- include/m_plugin.h | 18 ++++++++++++++++-- include/m_protocols.h | 17 +++++++---------- 2 files changed, 23 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/m_plugin.h b/include/m_plugin.h index 592aa565bf..ae56eeb49a 100644 --- a/include/m_plugin.h +++ b/include/m_plugin.h @@ -4,6 +4,8 @@ #include #include +extern HINSTANCE g_hInstance; + class MIR_APP_EXPORT CMPluginBase { void tryOpenLog(); @@ -11,8 +13,9 @@ class MIR_APP_EXPORT CMPluginBase protected: const char *m_szModuleName; HANDLE m_hLogger = nullptr; + HINSTANCE m_hInst; - CMPluginBase(const char *moduleName); + CMPluginBase(HINSTANCE, const char *moduleName); ~CMPluginBase(); // pass one of PROTOTYPE_* constants as type @@ -26,6 +29,8 @@ public: void debugLogA(LPCSTR szFormat, ...); void debugLogW(LPCWSTR wszFormat, ...); + __forceinline HINSTANCE getInst() const { return m_hInst; } + __forceinline INT_PTR delSetting(const char *name) { return db_unset(0, m_szModuleName, name); @@ -158,13 +163,22 @@ extern struct CMPlugin g_plugin; ///////////////////////////////////////////////////////////////////////////////////////// // Basic class for plugins (not protocols) written in C++ +typedef BOOL(WINAPI * const _pfnCrtInit)(HINSTANCE, DWORD, LPVOID); + template class PLUGIN : public CMPluginBase { typedef CMPluginBase CSuper; +public: + static BOOL WINAPI RawDllMain(HINSTANCE hInstance, DWORD, LPVOID) + { + g_hInstance = hInstance; + return TRUE; + } + protected: PLUGIN(const char *moduleName) - : CSuper(moduleName) + : CSuper(g_hInstance, moduleName) {} __forceinline HANDLE CreatePluginEvent(const char *name) diff --git a/include/m_protocols.h b/include/m_protocols.h index 3c8a70a444..db32e1f94a 100644 --- a/include/m_protocols.h +++ b/include/m_protocols.h @@ -151,20 +151,17 @@ typedef struct PROTO_INTERFACE* (*pfnInitProto)(const char* szModuleName, const // deallocates an account instance typedef int (*pfnUninitProto)(PROTO_INTERFACE*); -// removes an account from the database -typedef int (*pfnDestroyProto)(PROTO_INTERFACE*); - -typedef struct { +struct PROTOCOLDESCRIPTOR +{ size_t cbSize; char *szName; // unique name of the module int type; // module type, see PROTOTYPE_ constants - // 0.8.0+ additions - pfnInitProto fnInit; // initializes an empty account - pfnUninitProto fnUninit; // deallocates an account instance - pfnDestroyProto fnDestroy; // removes an account -} - PROTOCOLDESCRIPTOR; + // these fields should be filled only for protos with accounts + pfnInitProto fnInit; // initializes an empty account + pfnUninitProto fnUninit; // deallocates an account instance + HINSTANCE hInst; // module to which that proto belongs to +}; ///////////////////////////////////////////////////////////////////////////////////////// // Enumerate the currently running protocols -- cgit v1.2.3