summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-18 18:14:33 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-18 18:14:33 +0300
commitb172c4bbc75cdad0e8ccd22292aa671ba43cac45 (patch)
tree4677a04a47f3987c88f3fb44c6b70d2642b1f8a3 /include
parent524d1c7186eca3f0a4da08548eeb919785227101 (diff)
PLUGIN<> to half-automatically calculate the dll's g_hInstance and pass it inside
Diffstat (limited to 'include')
-rw-r--r--include/m_plugin.h18
-rw-r--r--include/m_protocols.h17
2 files changed, 23 insertions, 12 deletions
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 <m_database.h>
#include <m_protocols.h>
+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 T> 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