From 9cf1444eb7888f2d942d220f938aa893396a8a1b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 18 Apr 2018 20:51:18 +0300 Subject: g_hInstance incapulated into PLUGIN<>, no need in the separate variable --- plugins/ConnectionNotify/src/ConnectionNotify.cpp | 63 +++++++++-------------- plugins/ConnectionNotify/src/filter.cpp | 3 +- plugins/ConnectionNotify/src/stdafx.h | 9 ++++ 3 files changed, 35 insertions(+), 40 deletions(-) (limited to 'plugins/ConnectionNotify') diff --git a/plugins/ConnectionNotify/src/ConnectionNotify.cpp b/plugins/ConnectionNotify/src/ConnectionNotify.cpp index c53ac57712..7b2c7b0fd7 100644 --- a/plugins/ConnectionNotify/src/ConnectionNotify.cpp +++ b/plugins/ConnectionNotify/src/ConnectionNotify.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" -HINSTANCE g_hInstance; CLIST_INTERFACE *pcli; //PLUGINLINK *pluginLink=NULL; @@ -54,12 +53,23 @@ PLUGININFOEX pluginInfo = { { 0x4bb5b4aa, 0xc364, 0x4f23, { 0x97, 0x46, 0xd5, 0xb7, 0x8, 0xa2, 0x86, 0xa5 } } }; +extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD) +{ + return &pluginInfo; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +CMPlugin g_plugin; + +extern "C" _pfnCrtInit _pRawDllMain = &CMPlugin::RawDllMain; + +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; +///////////////////////////////////////////////////////////////////////////////////////// // authentication callback futnction from extension manager -// ====================================== -//========================================================================================= - BOOL strrep(wchar_t *src, wchar_t *needle, wchar_t *newstring) { @@ -83,11 +93,6 @@ BOOL strrep(wchar_t *src, wchar_t *needle, wchar_t *newstring) return TRUE; } -extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfo; -} - void saveSettingsConnections(struct CONNECTION *connHead) { char buff[128]; @@ -319,10 +324,10 @@ INT_PTR CALLBACK DlgProcConnectionNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wPar hwnd = GetDlgItem(hwndDlg, IDC_FGCOLOR); EnableWindow(hwnd, FALSE); } - SendDlgItemMessage(hwndDlg, ID_ADD, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ICON6), IMAGE_ICON, 16, 16, 0)); - SendDlgItemMessage(hwndDlg, ID_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ICON3), IMAGE_ICON, 16, 16, 0)); - SendDlgItemMessage(hwndDlg, ID_DOWN, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ICON4), IMAGE_ICON, 16, 16, 0)); - SendDlgItemMessage(hwndDlg, ID_UP, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ICON5), IMAGE_ICON, 16, 16, 0)); + SendDlgItemMessage(hwndDlg, ID_ADD, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_ICON6), IMAGE_ICON, 16, 16, 0)); + SendDlgItemMessage(hwndDlg, ID_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_ICON3), IMAGE_ICON, 16, 16, 0)); + SendDlgItemMessage(hwndDlg, ID_DOWN, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_ICON4), IMAGE_ICON, 16, 16, 0)); + SendDlgItemMessage(hwndDlg, ID_UP, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_ICON5), IMAGE_ICON, 16, 16, 0)); // initialise and fill listbox hwndList = GetDlgItem(hwndDlg, IDC_STATUS); ListView_DeleteAllItems(hwndList); @@ -388,7 +393,7 @@ INT_PTR CALLBACK DlgProcConnectionNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wPar cur->strExtIp[0] = '*'; cur->strIntIp[0] = '*'; - if (DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_FILTER_DIALOG), hwndDlg, FilterEditProc, (LPARAM)cur) == IDCANCEL) { + if (DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FILTER_DIALOG), hwndDlg, FilterEditProc, (LPARAM)cur) == IDCANCEL) { mir_free(cur); cur = nullptr; } @@ -552,7 +557,7 @@ INT_PTR CALLBACK DlgProcConnectionNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wPar while (pos--) { cur = cur->next; } - DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_FILTER_DIALOG), hwndDlg, FilterEditProc, (LPARAM)cur); + DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FILTER_DIALOG), hwndDlg, FilterEditProc, (LPARAM)cur); fillExceptionsListView(hwndDlg); ListView_SetItemState(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS), pos1, LVNI_FOCUSED | LVIS_SELECTED, LVNI_FOCUSED | LVIS_SELECTED); SetFocus(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS)); @@ -585,7 +590,7 @@ INT_PTR CALLBACK DlgProcConnectionNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wPar int ConnectionNotifyOptInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = {}; - odp.hInstance = g_hInstance; + odp.hInstance = g_plugin.getInst(); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_DIALOG); odp.szTitle.w = _A2W(PLUGINNAME); odp.szGroup.w = LPGENW("Plugins"); @@ -626,7 +631,7 @@ INT_PTR TMLoadIcon(WPARAM wParam, LPARAM) default: return 0; } - return (INT_PTR)LoadImage(g_hInstance, MAKEINTRESOURCE(id), IMAGE_ICON, GetSystemMetrics(wParam&PLIF_SMALL ? SM_CXSMICON : SM_CXICON), GetSystemMetrics(wParam&PLIF_SMALL ? SM_CYSMICON : SM_CYICON), 0); + return (INT_PTR)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(id), IMAGE_ICON, GetSystemMetrics(wParam&PLIF_SMALL ? SM_CXSMICON : SM_CXICON), GetSystemMetrics(wParam&PLIF_SMALL ? SM_CYSMICON : SM_CYICON), 0); } //======================================================= //SetStatus @@ -775,7 +780,7 @@ void showMsg(wchar_t *pName, DWORD pid, wchar_t *intIp, wchar_t *extIp, int intP //MessageBox(NULL,"aaa","aaa",1); memset(&ppd, 0, sizeof(ppd)); //This is always a good thing to do. ppd.lchContact = NULL;//(HANDLE)hContact; //Be sure to use a GOOD handle, since this will not be checked. - ppd.lchIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ICON1)); + ppd.lchIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_ICON1)); if (settingResolveIp) { wchar_t hostName[128]; getDnsName(extIp, hostName, _countof(hostName)); @@ -839,12 +844,6 @@ static int preshutdown(WPARAM, LPARAM) return 0; } -extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) -{ - g_hInstance = hinstDLL; - return TRUE; -} - extern "C" int __declspec(dllexport) Load(void) { #ifdef _DEBUG @@ -878,6 +877,8 @@ extern "C" int __declspec(dllexport) Load(void) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" int __declspec(dllexport) Unload(void) { WaitForSingleObjectEx(hConnectionCheckThread, INFINITE, FALSE); @@ -897,17 +898,3 @@ extern "C" int __declspec(dllexport) Unload(void) #endif return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -struct CMPlugin : public PLUGIN -{ - CMPlugin() : - PLUGIN(PLUGINNAME) - { - RegisterProtocol(PROTOTYPE_PROTOCOL); - } -} - g_plugin; - -extern "C" _pfnCrtInit _pRawDllMain = &CMPlugin::RawDllMain; diff --git a/plugins/ConnectionNotify/src/filter.cpp b/plugins/ConnectionNotify/src/filter.cpp index a9d9774048..faad01bc96 100644 --- a/plugins/ConnectionNotify/src/filter.cpp +++ b/plugins/ConnectionNotify/src/filter.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" HWND filterAddDlg = nullptr; -extern HINSTANCE g_hInstance; extern struct CONNECTION *connExceptions; extern HANDLE hFilterOptionsThread; extern DWORD FilterOptionsThreadId; @@ -27,7 +26,7 @@ static unsigned __stdcall filterQueue(void *) if (msg.message == WM_ADD_FILTER) { struct CONNECTION *conn = (struct CONNECTION *)msg.lParam; - filterAddDlg = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_FILTER_DIALOG), nullptr, ConnectionFilterEditProc, (LPARAM)conn); + filterAddDlg = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FILTER_DIALOG), nullptr, ConnectionFilterEditProc, (LPARAM)conn); ShowWindow(filterAddDlg, SW_SHOW); } diff --git a/plugins/ConnectionNotify/src/stdafx.h b/plugins/ConnectionNotify/src/stdafx.h index 32187cefcd..fda6ae7b09 100644 --- a/plugins/ConnectionNotify/src/stdafx.h +++ b/plugins/ConnectionNotify/src/stdafx.h @@ -39,6 +39,15 @@ #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(PLUGINNAME) + { + RegisterProtocol(PROTOTYPE_PROTOCOL); + } +}; + void showMsg(wchar_t *pName,DWORD pid,wchar_t *intIp,wchar_t *extIp,int intPort,int extPort,int state); //int __declspec(dllexport) Load(PLUGINLINK *link); extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); -- cgit v1.2.3