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 --- plugins/NewsAggregator/Src/Authentication.cpp | 2 +- plugins/NewsAggregator/Src/Icons.cpp | 2 +- plugins/NewsAggregator/Src/NewsAggregator.cpp | 24 ++++++++++++++---------- plugins/NewsAggregator/Src/Options.cpp | 10 +++++----- plugins/NewsAggregator/Src/stdafx.h | 2 +- 5 files changed, 22 insertions(+), 18 deletions(-) (limited to 'plugins/NewsAggregator') diff --git a/plugins/NewsAggregator/Src/Authentication.cpp b/plugins/NewsAggregator/Src/Authentication.cpp index 7ff29ede9a..e656206e9f 100644 --- a/plugins/NewsAggregator/Src/Authentication.cpp +++ b/plugins/NewsAggregator/Src/Authentication.cpp @@ -43,7 +43,7 @@ void CreateAuthString(char *auth, MCONTACT hContact, CFeedEditor *pDlg) } CAuthRequest::CAuthRequest(CFeedEditor *pDlg, MCONTACT hContact) - : CSuper(hInst, IDD_AUTHENTICATION), + : CSuper(g_hInstance, IDD_AUTHENTICATION), m_feedname(this, IDC_FEEDNAME), m_username(this, IDC_FEEDUSERNAME), m_password(this, IDC_FEEDPASSWORD), m_ok(this, IDOK) { diff --git a/plugins/NewsAggregator/Src/Icons.cpp b/plugins/NewsAggregator/Src/Icons.cpp index 763890c580..206238b4bd 100644 --- a/plugins/NewsAggregator/Src/Icons.cpp +++ b/plugins/NewsAggregator/Src/Icons.cpp @@ -33,7 +33,7 @@ static IconItem iconList[] = void InitIcons() { - Icon_Register(hInst, LPGEN("News Aggregator"), iconList, _countof(iconList), MODULE); + Icon_Register(g_hInstance, LPGEN("News Aggregator"), iconList, _countof(iconList), MODULE); } HICON LoadIconEx(const char *name, bool big) diff --git a/plugins/NewsAggregator/Src/NewsAggregator.cpp b/plugins/NewsAggregator/Src/NewsAggregator.cpp index d0b1547f22..66f0af69b8 100644 --- a/plugins/NewsAggregator/Src/NewsAggregator.cpp +++ b/plugins/NewsAggregator/Src/NewsAggregator.cpp @@ -19,7 +19,7 @@ Boston, MA 02111-1307, USA. #include "stdafx.h" -HINSTANCE hInst = nullptr; +HINSTANCE g_hInstance = nullptr; int hLangpack; HANDLE hPrebuildMenuHook = nullptr; @@ -29,6 +29,8 @@ HANDLE hUpdateMutex; LIST g_arFeeds(1, PtrKeySortT); +///////////////////////////////////////////////////////////////////////////////////////// + PLUGININFOEX pluginInfoEx = { sizeof(PLUGININFOEX), __PLUGIN_NAME, @@ -42,18 +44,16 @@ PLUGININFOEX pluginInfoEx = { {0x56cc3f29, 0xccbf, 0x4546, {0xa8, 0xba, 0x98, 0x56, 0x24, 0x8a, 0x41, 0x2a}} }; -bool WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) { - hInst = hinstDLL; - return TRUE; + return &pluginInfoEx; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfoEx; -} +///////////////////////////////////////////////////////////////////////////////////////// extern "C" __declspec(dllexport) int Load(void) { @@ -97,6 +97,8 @@ extern "C" __declspec(dllexport) int Load(void) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" __declspec(dllexport) int Unload(void) { DestroyUpdateList(); @@ -106,13 +108,15 @@ extern "C" __declspec(dllexport) int Unload(void) ///////////////////////////////////////////////////////////////////////////////////////// -struct CMPlugin : public CMPluginBase +struct CMPlugin : public PLUGIN { CMPlugin() : - CMPluginBase(MODULE) + PLUGIN(MODULE) { RegisterProtocol(PROTOTYPE_VIRTUAL); SetUniqueId("URL"); } } g_plugin; + +extern "C" _pfnCrtInit _pRawDllMain = &CMPlugin::RawDllMain; diff --git a/plugins/NewsAggregator/Src/Options.cpp b/plugins/NewsAggregator/Src/Options.cpp index b84aabe6a2..4d96fb10e3 100644 --- a/plugins/NewsAggregator/Src/Options.cpp +++ b/plugins/NewsAggregator/Src/Options.cpp @@ -20,7 +20,7 @@ Boston, MA 02111-1307, USA. #include "stdafx.h" CExportFeed::CExportFeed() - : CSuper(hInst, IDD_FEEDEXPORT), + : CSuper(g_hInstance, IDD_FEEDEXPORT), m_feedslist(this, IDC_FEEDSLIST), m_feedsexportlist(this, IDC_FEEDSEXPORTLIST), m_addfeed(this, IDC_ADDFEED), m_removefeed(this, IDC_REMOVEFEED), m_addallfeeds(this, IDC_ADDALLFEEDS), m_removeallfeeds(this, IDC_REMOVEALLFEEDS), @@ -251,7 +251,7 @@ void CExportFeed::OnClose() } CImportFeed::CImportFeed(CCtrlListView *m_feeds) - : CSuper(hInst, IDD_FEEDIMPORT), + : CSuper(g_hInstance, IDD_FEEDIMPORT), m_importfile(this, IDC_IMPORTFILEPATH), m_browsefile(this, IDC_BROWSEIMPORTFILE), m_feedslist(this, IDC_FEEDSLIST), m_feedsimportlist(this, IDC_FEEDSIMPORTLIST), m_addfeed(this, IDC_ADDFEED), m_removefeed(this, IDC_REMOVEFEED), @@ -661,7 +661,7 @@ void CImportFeed::OnClose() } CFeedEditor::CFeedEditor(int iItem, CCtrlListView *m_feeds, MCONTACT Contact) - : CSuper(hInst, IDD_ADDFEED), + : CSuper(g_hInstance, IDD_ADDFEED), m_feedtitle(this, IDC_FEEDTITLE), m_feedurl(this, IDC_FEEDURL), m_checktime(this, IDC_CHECKTIME), m_checktimespin(this, IDC_TIMEOUT_VALUE_SPIN), m_checkfeed(this, IDC_DISCOVERY), m_useauth(this, IDC_USEAUTH), @@ -893,7 +893,7 @@ void COptionsMain::UpdateList() } COptionsMain::COptionsMain() - : CPluginDlgBase(hInst, IDD_OPTIONS, MODULE), + : CPluginDlgBase(g_hInstance, IDD_OPTIONS, MODULE), m_feeds(this, IDC_FEEDLIST), m_add(this, IDC_ADD), m_change(this, IDC_CHANGE), @@ -1064,7 +1064,7 @@ void COptionsMain::OnFeedListDoubleClick(CCtrlBase*) int OptInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; - odp.hInstance = hInst; + odp.hInstance = g_hInstance; odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE; odp.szGroup.w = LPGENW("Network"); odp.szTitle.w = LPGENW("News Aggregator"); diff --git a/plugins/NewsAggregator/Src/stdafx.h b/plugins/NewsAggregator/Src/stdafx.h index 40fc6f7002..60c5bcf593 100644 --- a/plugins/NewsAggregator/Src/stdafx.h +++ b/plugins/NewsAggregator/Src/stdafx.h @@ -60,7 +60,7 @@ Boston, MA 02111-1307, USA. #define DEFAULT_AVATARS_FOLDER "NewsAggregator" #define DEFAULT_UPDATE_TIME 60 -extern HINSTANCE hInst; +extern HINSTANCE g_hInstance; extern CDlgBase *pAddFeedDialog, *pImportDialog, *pExportDialog; extern HNETLIBUSER hNetlibUser; extern UINT_PTR timerId; -- cgit v1.2.3