From 0bd2aba7306dd3f1f2118c0c1a6cb751dea8dce0 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Wed, 16 May 2018 10:05:44 +0300 Subject: AssocMgr: cmplugin adaptation --- plugins/AssocMgr/src/assoclist.cpp | 235 ++++++++++++++++++------------------- plugins/AssocMgr/src/dde.cpp | 57 +++++---- plugins/AssocMgr/src/main.cpp | 14 +-- plugins/AssocMgr/src/reg.cpp | 6 +- plugins/AssocMgr/src/stdafx.h | 9 +- plugins/AssocMgr/src/utils.cpp | 82 ++++++------- 6 files changed, 198 insertions(+), 205 deletions(-) (limited to 'plugins/AssocMgr') diff --git a/plugins/AssocMgr/src/assoclist.cpp b/plugins/AssocMgr/src/assoclist.cpp index 8a8bd298fc..43c538eb2c 100644 --- a/plugins/AssocMgr/src/assoclist.cpp +++ b/plugins/AssocMgr/src/assoclist.cpp @@ -9,7 +9,7 @@ modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. -This program is distributed in the hope that it will be useful, +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" // Options -extern HINSTANCE hInst; static HANDLE hHookOptInit; /************************* Assoc List *****************************/ @@ -60,7 +59,7 @@ static void SetAssocEnabled(const ASSOCDATA *assoc, BOOL fEnabled) mir_snprintf(szSetting, "enabled_%s", assoc->pszClassName); db_set_b(NULL, "AssocMgr", szSetting, (BYTE)fEnabled); // dll name for uninstall - if (assoc->hInstance != nullptr && assoc->hInstance != hInst && assoc->hInstance != GetModuleHandle(nullptr)) + if (assoc->hInstance != nullptr && assoc->hInstance != g_plugin.getInst() && assoc->hInstance != GetModuleHandle(nullptr)) if (GetModuleFileName(assoc->hInstance, szBuf, _countof(szBuf))) if (PathToRelativeW(szBuf, szDLL)) { mir_snprintf(szSetting, "module_%s", assoc->pszClassName); @@ -309,7 +308,7 @@ static BOOL EnsureAssocRegistered(const ASSOCDATA *assoc) if (!IsRegClass(assoc->pszClassName, pszRunCmd)) { // class icon if (!assoc->nIconResID && fIsUrl) pszIconLoc = MakeIconLocation(nullptr, 0); // miranda logo - else if (!assoc->nIconResID) pszIconLoc = MakeIconLocation(hInst, IDI_MIRANDAFILE); // generic file + else if (!assoc->nIconResID) pszIconLoc = MakeIconLocation(g_plugin.getInst(), IDI_MIRANDAFILE); // generic file else pszIconLoc = MakeIconLocation(assoc->hInstance, assoc->nIconResID); // register class if (fUseMainCmdLine) pszDdeCmd = nullptr; @@ -401,7 +400,7 @@ static BOOL AddNewAssocItem_Worker(char *pszClassName, const TYPEDESCHEAD *tdh, if (index != -1) return FALSE; // resize storage array - pAssocListBuf = (ASSOCDATA*)mir_realloc(pAssocList, (nAssocListCount + 1)*sizeof(ASSOCDATA)); + pAssocListBuf = (ASSOCDATA*)mir_realloc(pAssocList, (nAssocListCount + 1) * sizeof(ASSOCDATA)); if (pAssocListBuf == nullptr) return FALSE; pAssocList = pAssocListBuf; @@ -462,8 +461,8 @@ static BOOL RemoveAssocItem_Worker(const char *pszClassName) // resize storage array if ((index + 1) < nAssocListCount) - memmove(assoc, &pAssocList[index + 1], ((nAssocListCount - index - 1)*sizeof(ASSOCDATA))); - pAssocListBuf = (ASSOCDATA*)mir_realloc(pAssocList, (nAssocListCount - 1)*sizeof(ASSOCDATA)); + memmove(assoc, &pAssocList[index + 1], ((nAssocListCount - index - 1) * sizeof(ASSOCDATA))); + pAssocListBuf = (ASSOCDATA*)mir_realloc(pAssocList, (nAssocListCount - 1) * sizeof(ASSOCDATA)); if (pAssocListBuf != nullptr) pAssocList = pAssocListBuf; --nAssocListCount; @@ -650,125 +649,125 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara switch (msg) { case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + CoInitialize(nullptr); + HWND hwndList = GetDlgItem(hwndDlg, IDC_ASSOCLIST); + + ListView_SetUnicodeFormat(hwndList, TRUE); + + SendDlgItemMessage(hwndDlg, IDC_HEADERTEXT, WM_SETFONT, SendMessage(GetParent(hwndDlg), PSM_GETBOLDFONT, 0, 0), 0); + // checkboxes won't show up on Win95 without IE3+ or 4.70 (plugin opts uses the same) + ListView_SetExtendedListViewStyle(hwndList, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP); + // columns + { + LVCOLUMN lvc; + lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; + lvc.pszText = TranslateT("Type"); + lvc.cx = 170; + ListView_InsertColumn(hwndList, lvc.iSubItem = 0, &lvc); + lvc.pszText = TranslateT("Description"); + ListView_InsertColumn(hwndList, lvc.iSubItem = 1, &lvc); + } + // create image storage + HIMAGELIST himl; + mir_cslock lck(csAssocList); { - TranslateDialogDefault(hwndDlg); - CoInitialize(nullptr); - HWND hwndList = GetDlgItem(hwndDlg, IDC_ASSOCLIST); - - ListView_SetUnicodeFormat(hwndList, TRUE); - - SendDlgItemMessage(hwndDlg, IDC_HEADERTEXT, WM_SETFONT, SendMessage(GetParent(hwndDlg), PSM_GETBOLDFONT, 0, 0), 0); - // checkboxes won't show up on Win95 without IE3+ or 4.70 (plugin opts uses the same) - ListView_SetExtendedListViewStyle(hwndList, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP); - // columns - { - LVCOLUMN lvc; - lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; - lvc.pszText = TranslateT("Type"); - lvc.cx = 170; - ListView_InsertColumn(hwndList, lvc.iSubItem = 0, &lvc); - lvc.pszText = TranslateT("Description"); - ListView_InsertColumn(hwndList, lvc.iSubItem = 1, &lvc); + HDC hdc = GetDC(hwndList); + if (hdc != nullptr) { // BITSPIXEL is compatible with ILC_COLOR flags + himl = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), GetDeviceCaps(hdc, BITSPIXEL) | ILC_MASK, nAssocListCount, 0); + ReleaseDC(hwndList, hdc); } - // create image storage - HIMAGELIST himl; - mir_cslock lck(csAssocList); - { - HDC hdc = GetDC(hwndList); - if (hdc != nullptr) { // BITSPIXEL is compatible with ILC_COLOR flags - himl = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), GetDeviceCaps(hdc, BITSPIXEL) | ILC_MASK, nAssocListCount, 0); - ReleaseDC(hwndList, hdc); - } - else himl = nullptr; + else himl = nullptr; + } + ListView_SetImageList(hwndList, himl, LVSIL_SMALL); // autodestroyed + // enum assoc list + lvi.iSubItem = 0; + lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; + for (int i = 0; i < nAssocListCount; ++i) { + assoc = &pAssocList[i]; + lvi.iItem = 0; + lvi.lParam = (LPARAM)CopyAssocItem(assoc); + lvi.pszText = GetAssocTypeDesc(assoc); + lvi.iImage = ReplaceImageListAssocIcon(himl, assoc, -1); + lvi.iItem = ListView_InsertItem(hwndList, &lvi); + if (lvi.iItem != -1) { + ListView_SetItemText(hwndList, lvi.iItem, 1, assoc->pszDescription); + ListView_SetCheckState(hwndList, lvi.iItem, IsAssocEnabled(assoc) && IsAssocRegistered(assoc)); } - ListView_SetImageList(hwndList, himl, LVSIL_SMALL); // autodestroyed - // enum assoc list + } + // sort items (before moving to groups) + ListView_SortItems(hwndList, ListViewSortDesc, Langpack_GetDefaultLocale()); + // groups + if (ListView_EnableGroupView(hwndList, TRUE) == 1) { // returns 0 on pre WinXP or if commctls6 are disabled + LVGROUP lvg; + int iItem; + // dummy item for group + lvi.iItem = ListView_GetItemCount(hwndList) - 1; lvi.iSubItem = 0; - lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; - for (int i = 0; i < nAssocListCount; ++i) { - assoc = &pAssocList[i]; - lvi.iItem = 0; - lvi.lParam = (LPARAM)CopyAssocItem(assoc); - lvi.pszText = GetAssocTypeDesc(assoc); - lvi.iImage = ReplaceImageListAssocIcon(himl, assoc, -1); - lvi.iItem = ListView_InsertItem(hwndList, &lvi); - if (lvi.iItem != -1) { - ListView_SetItemText(hwndList, lvi.iItem, 1, assoc->pszDescription); - ListView_SetCheckState(hwndList, lvi.iItem, IsAssocEnabled(assoc) && IsAssocRegistered(assoc)); - } - } - // sort items (before moving to groups) - ListView_SortItems(hwndList, ListViewSortDesc, Langpack_GetDefaultLocale()); - // groups - if (ListView_EnableGroupView(hwndList, TRUE) == 1) { // returns 0 on pre WinXP or if commctls6 are disabled - LVGROUP lvg; - int iItem; - // dummy item for group - lvi.iItem = ListView_GetItemCount(hwndList) - 1; - lvi.iSubItem = 0; - lvi.mask = LVIF_PARAM | LVIF_IMAGE; - lvi.iImage = -1; - lvi.lParam = 0; - // insert groups - lvg.cbSize = sizeof(lvg); - lvg.mask = LVGF_HEADER | LVGF_GROUPID; - lvg.iGroupId = 2; - lvg.pszHeader = TranslateT("URLs on websites"); - lvi.iItem = ListView_InsertItem(hwndList, &lvi); - if (lvi.iItem != -1) { + lvi.mask = LVIF_PARAM | LVIF_IMAGE; + lvi.iImage = -1; + lvi.lParam = 0; + // insert groups + lvg.cbSize = sizeof(lvg); + lvg.mask = LVGF_HEADER | LVGF_GROUPID; + lvg.iGroupId = 2; + lvg.pszHeader = TranslateT("URLs on websites"); + lvi.iItem = ListView_InsertItem(hwndList, &lvi); + if (lvi.iItem != -1) { + ListView_InsertGroup(hwndList, lvi.iItem, &lvg); + lvg.iGroupId = 1; + lvg.pszHeader = TranslateT("File types"); + iItem = lvi.iItem = ListView_InsertItem(hwndList, &lvi); + if (lvi.iItem != -1) ListView_InsertGroup(hwndList, lvi.iItem, &lvg); - lvg.iGroupId = 1; - lvg.pszHeader = TranslateT("File types"); - iItem = lvi.iItem = ListView_InsertItem(hwndList, &lvi); - if (lvi.iItem != -1) - ListView_InsertGroup(hwndList, lvi.iItem, &lvg); - else ListView_DeleteItem(hwndList, iItem); - } - // move to group - lvi.iSubItem = 0; - lvi.mask = LVIF_PARAM | LVIF_GROUPID; - for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) { - assoc = (ASSOCDATA*)lvi.lParam; - if (assoc == nullptr) continue; // groups - lvi.iGroupId = (assoc->pszFileExt == nullptr) + 1; - ListView_SetItem(hwndList, &lvi); - } + else ListView_DeleteItem(hwndList, iItem); } - lvi.iItem = ListView_GetTopIndex(hwndList); - ListView_SetItemState(hwndList, lvi.iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE_USEHEADER); // size to fit window - // only while running - CheckDlgButton(hwndDlg, IDC_ONLYWHILERUNNING, (BOOL)db_get_b(NULL, "AssocMgr", "OnlyWhileRunning", SETTING_ONLYWHILERUNNING_DEFAULT) ? BST_CHECKED : BST_UNCHECKED); - - // autostart - wchar_t *pszRunCmd = MakeRunCommand(TRUE, TRUE); - if (pszRunCmd != nullptr) { - CheckDlgButton(hwndDlg, IDC_AUTOSTART, IsRegRunEntry(L"MirandaNG", pszRunCmd) ? BST_CHECKED : BST_UNCHECKED); - mir_free(pszRunCmd); - } - } - return TRUE; - - case WM_SETTINGCHANGE: - case M_REFRESH_ICONS: - { - HWND hwndList = GetDlgItem(hwndDlg, IDC_ASSOCLIST); - HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_SMALL); - // enum items + // move to group lvi.iSubItem = 0; - lvi.mask = LVIF_PARAM | LVIF_IMAGE; + lvi.mask = LVIF_PARAM | LVIF_GROUPID; for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) { assoc = (ASSOCDATA*)lvi.lParam; if (assoc == nullptr) continue; // groups - lvi.iImage = ReplaceImageListAssocIcon(himl, assoc, lvi.iImage); + lvi.iGroupId = (assoc->pszFileExt == nullptr) + 1; ListView_SetItem(hwndList, &lvi); } - if (lvi.iItem) { // ListView_Update() blinks - ListView_RedrawItems(hwndList, 0, lvi.iItem - 1); - UpdateWindow(hwndList); - } } - return TRUE; + lvi.iItem = ListView_GetTopIndex(hwndList); + ListView_SetItemState(hwndList, lvi.iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE_USEHEADER); // size to fit window + // only while running + CheckDlgButton(hwndDlg, IDC_ONLYWHILERUNNING, (BOOL)db_get_b(NULL, "AssocMgr", "OnlyWhileRunning", SETTING_ONLYWHILERUNNING_DEFAULT) ? BST_CHECKED : BST_UNCHECKED); + + // autostart + wchar_t *pszRunCmd = MakeRunCommand(TRUE, TRUE); + if (pszRunCmd != nullptr) { + CheckDlgButton(hwndDlg, IDC_AUTOSTART, IsRegRunEntry(L"MirandaNG", pszRunCmd) ? BST_CHECKED : BST_UNCHECKED); + mir_free(pszRunCmd); + } + } + return TRUE; + + case WM_SETTINGCHANGE: + case M_REFRESH_ICONS: + { + HWND hwndList = GetDlgItem(hwndDlg, IDC_ASSOCLIST); + HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_SMALL); + // enum items + lvi.iSubItem = 0; + lvi.mask = LVIF_PARAM | LVIF_IMAGE; + for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) { + assoc = (ASSOCDATA*)lvi.lParam; + if (assoc == nullptr) continue; // groups + lvi.iImage = ReplaceImageListAssocIcon(himl, assoc, lvi.iImage); + ListView_SetItem(hwndList, &lvi); + } + if (lvi.iItem) { // ListView_Update() blinks + ListView_RedrawItems(hwndList, 0, lvi.iItem - 1); + UpdateWindow(hwndList); + } + } + return TRUE; case WM_CTLCOLORSTATIC: // use same text color for header as for group boxes (WinXP+) @@ -799,7 +798,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara return TRUE; case WM_NOTIFY: - NMHDR *nmhdr = (NMHDR*)lParam; + NMHDR * nmhdr = (NMHDR*)lParam; switch (nmhdr->idFrom) { case IDC_ASSOCLIST: switch (nmhdr->code) { @@ -817,7 +816,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara if (IsWindowVisible(nmhdr->hwndFrom)) PostMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); return TRUE; - + case LVN_KEYDOWN: // workaround for WinXP (ListView with groups): // eat keyboard navigation that goes beyond the first item in list @@ -914,7 +913,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara static int AssocListOptInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; - odp.hInstance = hInst; + odp.hInstance = g_plugin.getInst(); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_ASSOCLIST); odp.position = 900000100; // network opts = 900000000 odp.szGroup.a = LPGEN("Services"); // autotranslated @@ -979,7 +978,7 @@ void InitAssocList(void) ftd.pszFileExt = ".dat"; ftd.pszMimeType = nullptr; ftd.pwszDescription = TranslateT("Miranda NG database"); - ftd.hInstance = hInst; + ftd.hInstance = g_plugin.getInst(); ftd.nIconResID = IDI_MIRANDAFILE; ftd.pwszVerbDesc = nullptr; ftd.pszService = nullptr; @@ -1021,7 +1020,7 @@ void UninitAssocList(void) ptrW pszAppFileName(MakeAppFileName(TRUE)); if (pszAppFileName != NULL) RemoveRegOpenWith(pszAppFileName); - + // assocmgr.dll pszAppFileName = MakeAppFileName(FALSE); if (pszAppFileName != NULL) diff --git a/plugins/AssocMgr/src/dde.cpp b/plugins/AssocMgr/src/dde.cpp index d1b4f30fa5..0efa55102d 100644 --- a/plugins/AssocMgr/src/dde.cpp +++ b/plugins/AssocMgr/src/dde.cpp @@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" /* Conversation */ -extern HINSTANCE hInst; static HWND hwndDdeMsg; /* Misc */ static HANDLE hHookModulesLoaded, hHookPreShutdown; @@ -88,20 +87,20 @@ static LRESULT CALLBACK DdeMessageWindow(HWND hwnd, UINT msg, WPARAM wParam, LPA { switch (msg) { case WM_DDE_INITIATE: - { - ATOM hSzApp = LOWORD(lParam); /* no UnpackDDElParam() here */ - ATOM hSzTopic = HIWORD(lParam); - if ((hSzApp == GlobalFindAtom(DDEAPP) && hSzTopic == GlobalFindAtom(DDETOPIC)) || !hSzApp) { - hSzApp = GlobalAddAtom(DDEAPP); - hSzTopic = GlobalAddAtom(DDETOPIC); - if (hSzApp && hSzTopic) - /* PackDDElParam() only for posted msgs */ - SendMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(hSzApp, hSzTopic)); - if (hSzApp) GlobalDeleteAtom(hSzApp); - if (hSzTopic) GlobalDeleteAtom(hSzTopic); - } + { + ATOM hSzApp = LOWORD(lParam); /* no UnpackDDElParam() here */ + ATOM hSzTopic = HIWORD(lParam); + if ((hSzApp == GlobalFindAtom(DDEAPP) && hSzTopic == GlobalFindAtom(DDETOPIC)) || !hSzApp) { + hSzApp = GlobalAddAtom(DDEAPP); + hSzTopic = GlobalAddAtom(DDETOPIC); + if (hSzApp && hSzTopic) + /* PackDDElParam() only for posted msgs */ + SendMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(hSzApp, hSzTopic)); + if (hSzApp) GlobalDeleteAtom(hSzApp); + if (hSzTopic) GlobalDeleteAtom(hSzTopic); } - return 0; + } + return 0; case WM_DDE_EXECUTE: /* posted message */ HGLOBAL hCommand; @@ -143,19 +142,19 @@ static LRESULT CALLBACK DdeMessageWindow(HWND hwnd, UINT msg, WPARAM wParam, LPA case WM_DDE_UNADVISE: case WM_DDE_POKE: /* fail safely for those to avoid memory leak in lParam */ - { - ATOM hSzItem; - DDEACK ack; - memset(&ack, 0, sizeof(ack)); - if (UnpackDDElParam(msg, lParam, nullptr, (PUINT_PTR)&hSzItem)) { - lParam = ReuseDDElParam(lParam, msg, WM_DDE_ACK, *(PUINT)&ack, (UINT)hSzItem); - if (!PostMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, lParam)) { - if (hSzItem) GlobalDeleteAtom(hSzItem); - FreeDDElParam(WM_DDE_ACK, lParam); - } + { + ATOM hSzItem; + DDEACK ack; + memset(&ack, 0, sizeof(ack)); + if (UnpackDDElParam(msg, lParam, nullptr, (PUINT_PTR)&hSzItem)) { + lParam = ReuseDDElParam(lParam, msg, WM_DDE_ACK, *(PUINT)&ack, (UINT)hSzItem); + if (!PostMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, lParam)) { + if (hSzItem) GlobalDeleteAtom(hSzItem); + FreeDDElParam(WM_DDE_ACK, lParam); } - return 0; } + return 0; + } } return DefWindowProc(hwnd, msg, wParam, lParam); } @@ -166,7 +165,7 @@ static HANDLE StartupMainProcess(wchar_t *pszDatabasePath) wchar_t *p, szPath[MAX_PATH]; /* we are inside RunDll32 here */ - if (!GetModuleFileName(hInst, szPath, _countof(szPath))) return nullptr; + if (!GetModuleFileName(g_plugin.getInst(), szPath, _countof(szPath))) return nullptr; p = wcsrchr(szPath, '\\'); if (p != nullptr) { *p = 0; p = wcsrchr(szPath, '\\'); } if (p == nullptr) return nullptr; @@ -215,7 +214,7 @@ static int DdePreShutdown(WPARAM, LPARAM) { /* dde needs to be stopped before any plugins are unloaded */ if (hwndDdeMsg != nullptr) DestroyWindow(hwndDdeMsg); - UnregisterClass(WNDCLASS_DDEMSGWINDOW, hInst); + UnregisterClass(WNDCLASS_DDEMSGWINDOW, g_plugin.getInst()); return 0; } @@ -226,7 +225,7 @@ static int DdeModulesLoaded2(WPARAM, LPARAM) wcl.lpfnWndProc = DdeMessageWindow; wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; - wcl.hInstance = hInst; + wcl.hInstance = g_plugin.getInst(); wcl.hCursor = nullptr; wcl.lpszClassName = WNDCLASS_DDEMSGWINDOW; wcl.hbrBackground = nullptr; @@ -235,7 +234,7 @@ static int DdeModulesLoaded2(WPARAM, LPARAM) wcl.style = 0; RegisterClass(&wcl); /* Note: use of HWND_MESSAGE does not fit for DDE as the window must be a top-level one */ - hwndDdeMsg = CreateWindow(WNDCLASS_DDEMSGWINDOW, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr, hInst, nullptr); + hwndDdeMsg = CreateWindow(WNDCLASS_DDEMSGWINDOW, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr, g_plugin.getInst(), nullptr); /* make known dde startup code is passed */ HANDLE hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, WNDCLASS_DDEMSGWINDOW); diff --git a/plugins/AssocMgr/src/main.cpp b/plugins/AssocMgr/src/main.cpp index 7412c4e775..a498535497 100644 --- a/plugins/AssocMgr/src/main.cpp +++ b/plugins/AssocMgr/src/main.cpp @@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma comment(lib, "delayimp.lib") -HINSTANCE hInst; static HANDLE hHookModulesLoaded; +CMPlugin g_plugin; int hLangpack; PLUGININFOEX pluginInfo = { @@ -40,15 +40,7 @@ PLUGININFOEX pluginInfo = { {0x52685cd7, 0xec7, 0x44c1, {0xa1, 0xa6, 0x38, 0x16, 0x12, 0x41, 0x82, 0x2}} }; -///////////////////////////////////////////////////////////////////////////////////////// - -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) -{ - hInst = hinstDLL; - return TRUE; -} - -static int AssocMgrModulesLoaded(WPARAM,LPARAM) +static int AssocMgrModulesLoaded(WPARAM, LPARAM) { return 0; } @@ -65,7 +57,7 @@ extern "C" __declspec(dllexport) int Load(void) InitAssocList(); InitDde(); - hHookModulesLoaded=HookEvent(ME_SYSTEM_MODULESLOADED,AssocMgrModulesLoaded); + hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, AssocMgrModulesLoaded); return 0; } diff --git a/plugins/AssocMgr/src/reg.cpp b/plugins/AssocMgr/src/reg.cpp index 43976f1217..ee7f8745b2 100644 --- a/plugins/AssocMgr/src/reg.cpp +++ b/plugins/AssocMgr/src/reg.cpp @@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -extern HINSTANCE hInst; - #ifdef _DEBUG // Debug: Ensure all registry calls do succeed and have valid parameters. // Shows a details message box otherwise. @@ -135,7 +133,7 @@ wchar_t* MakeRunCommand(BOOL fMirExe, BOOL fFixedDbProfile) } else mir_wstrcpy(szDbFile, L"%1"); // buffer safe - if (!GetModuleFileName(fMirExe ? nullptr : hInst, szExe, _countof(szExe))) + if (!GetModuleFileName(fMirExe ? nullptr : g_plugin.getInst(), szExe, _countof(szExe))) return nullptr; if (fMirExe) @@ -214,7 +212,7 @@ wchar_t* MakeIconLocation(HMODULE hModule, WORD nIconResID) wchar_t* MakeAppFileName(BOOL fMirExe) { wchar_t szExe[MAX_PATH], *psz; - if (GetModuleFileName(fMirExe ? nullptr : hInst, szExe, _countof(szExe))) { + if (GetModuleFileName(fMirExe ? nullptr : g_plugin.getInst(), szExe, _countof(szExe))) { psz = wcsrchr(szExe, '\\'); if (psz != nullptr) ++psz; else psz = szExe; diff --git a/plugins/AssocMgr/src/stdafx.h b/plugins/AssocMgr/src/stdafx.h index 08009fb652..b68cbfd6db 100644 --- a/plugins/AssocMgr/src/stdafx.h +++ b/plugins/AssocMgr/src/stdafx.h @@ -29,8 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define DELAYIMP_INSECURE_WRITABLE_HOOKS #include -#define __NO_CMPLUGIN_NEEDED - #include #include #include @@ -46,3 +44,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "dde.h" #include "resource.h" #include "version.h" + +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN("AssocMgr") + {} +}; \ No newline at end of file diff --git a/plugins/AssocMgr/src/utils.cpp b/plugins/AssocMgr/src/utils.cpp index db1143432f..a97d257fc8 100644 --- a/plugins/AssocMgr/src/utils.cpp +++ b/plugins/AssocMgr/src/utils.cpp @@ -42,18 +42,18 @@ void DynamicLoadInit() /************************* String Conv ****************************/ // mir_free() the return value -WCHAR* a2u(const char *pszAnsi,BOOL fMirCp) +WCHAR* a2u(const char *pszAnsi, BOOL fMirCp) { - UINT codepage,cch; + UINT codepage, cch; WCHAR *psz; - - if(pszAnsi==nullptr) return nullptr; + + if (pszAnsi == nullptr) return nullptr; codepage = fMirCp ? Langpack_GetDefaultCodePage() : CP_ACP; - cch=MultiByteToWideChar(codepage,0,pszAnsi,-1,nullptr,0); + cch = MultiByteToWideChar(codepage, 0, pszAnsi, -1, nullptr, 0); if (!cch) return nullptr; - psz=(WCHAR*)mir_alloc(cch*sizeof(WCHAR)); - if(psz!=nullptr && !MultiByteToWideChar(codepage,0,pszAnsi,-1,psz,cch)) { + psz = (WCHAR*)mir_alloc(cch * sizeof(WCHAR)); + if (psz != nullptr && !MultiByteToWideChar(codepage, 0, pszAnsi, -1, psz, cch)) { mir_free(psz); return nullptr; } @@ -61,21 +61,21 @@ WCHAR* a2u(const char *pszAnsi,BOOL fMirCp) } // mir_free() the return value -char* u2a(const WCHAR *pszUnicode,BOOL fMirCp) -{ - UINT codepage,cch; +char* u2a(const WCHAR *pszUnicode, BOOL fMirCp) +{ + UINT codepage, cch; char *psz; DWORD flags; - if(pszUnicode==nullptr) return nullptr; + if (pszUnicode == nullptr) return nullptr; codepage = fMirCp ? Langpack_GetDefaultCodePage() : CP_ACP; /* without WC_COMPOSITECHECK some characters might get out strange (see MS blog) */ - cch=WideCharToMultiByte(codepage,flags=WC_COMPOSITECHECK,pszUnicode,-1,nullptr,0,nullptr,nullptr); - if (!cch) cch=WideCharToMultiByte(codepage,flags=0,pszUnicode,-1,nullptr,0,nullptr,nullptr); + cch = WideCharToMultiByte(codepage, flags = WC_COMPOSITECHECK, pszUnicode, -1, nullptr, 0, nullptr, nullptr); + if (!cch) cch = WideCharToMultiByte(codepage, flags = 0, pszUnicode, -1, nullptr, 0, nullptr, nullptr); if (!cch) return nullptr; - psz=(char*)mir_alloc(cch); - if(psz!=nullptr && !WideCharToMultiByte(codepage,flags,pszUnicode,-1,psz,cch,nullptr,nullptr)) { + psz = (char*)mir_alloc(cch); + if (psz != nullptr && !WideCharToMultiByte(codepage, flags, pszUnicode, -1, psz, cch, nullptr, nullptr)) { mir_free(psz); return nullptr; } @@ -83,19 +83,19 @@ char* u2a(const WCHAR *pszUnicode,BOOL fMirCp) } // mir_free() the return value -wchar_t* s2t(const void *pszStr,DWORD fUnicode,BOOL fMirCp) +wchar_t* s2t(const void *pszStr, DWORD fUnicode, BOOL fMirCp) { - if(fUnicode) return mir_wstrdup((WCHAR*)pszStr); - return a2u((char*)pszStr,fMirCp); + if (fUnicode) return mir_wstrdup((WCHAR*)pszStr); + return a2u((char*)pszStr, fMirCp); } // mir_free() the return value -void* t2s(const wchar_t *pszStr,DWORD fUnicode,BOOL fMirCp) +void* t2s(const wchar_t *pszStr, DWORD fUnicode, BOOL fMirCp) { - if (!fUnicode) return (void*)u2a(pszStr,fMirCp); + if (!fUnicode) return (void*)u2a(pszStr, fMirCp); return (void*)mir_wstrdup(pszStr); } @@ -111,22 +111,22 @@ struct EnumPrefixSettingsParams { static int EnumPrefixSettingsProc(const char *pszSetting, void *lParam) { - struct EnumPrefixSettingsParams *param=(struct EnumPrefixSettingsParams*)lParam; - if (!strncmp(pszSetting,param->pszPrefix,param->nPrefixLen)) { + struct EnumPrefixSettingsParams *param = (struct EnumPrefixSettingsParams*)lParam; + if (!strncmp(pszSetting, param->pszPrefix, param->nPrefixLen)) { char **buf; /* resize storage array */ - buf = (char**)mir_realloc(param->settings,(param->nSettingsCount+1)*sizeof(char*)); - if(buf!=nullptr) { - param->settings=buf; - buf[param->nSettingsCount]=mir_strdup(pszSetting); - if(buf[param->nSettingsCount]!=nullptr) ++param->nSettingsCount; + buf = (char**)mir_realloc(param->settings, (param->nSettingsCount + 1) * sizeof(char*)); + if (buf != nullptr) { + param->settings = buf; + buf[param->nSettingsCount] = mir_strdup(pszSetting); + if (buf[param->nSettingsCount] != nullptr) ++param->nSettingsCount; } } return 0; } // mir_free() the returned pSettings after use -BOOL EnumDbPrefixSettings(const char *pszModule,const char *pszSettingPrefix,char ***pSettings,int *pnSettingsCount) +BOOL EnumDbPrefixSettings(const char *pszModule, const char *pszSettingPrefix, char ***pSettings, int *pnSettingsCount) { struct EnumPrefixSettingsParams param; param.settings = nullptr; @@ -149,31 +149,31 @@ static void MessageBoxIndirectFree(MSGBOXPARAMSA *mbp) mir_free(mbp); } -void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...) +void ShowInfoMessage(BYTE flags, const char *pszTitle, const char *pszTextFmt, ...) { char szText[256]; /* max for systray */ va_list va; - va_start(va,pszTextFmt); - mir_vsnprintf(szText,_countof(szText),pszTextFmt,va); + va_start(va, pszTextFmt); + mir_vsnprintf(szText, _countof(szText), pszTextFmt, va); va_end(va); if (!Clist_TrayNotifyA(nullptr, pszTitle, szText, flags, 30000)) // success return; MSGBOXPARAMSA *mbp = (MSGBOXPARAMSA*)mir_calloc(sizeof(*mbp)); - if(mbp == nullptr) + if (mbp == nullptr) return; - + mbp->cbSize = sizeof(*mbp); mbp->lpszCaption = mir_strdup(pszTitle); mbp->lpszText = mir_strdup(szText); mbp->dwStyle = MB_OK | MB_SETFOREGROUND | MB_TASKMODAL; mbp->dwLanguageId = LANGIDFROMLCID(Langpack_GetDefaultLocale()); - switch(flags&NIIF_ICON_MASK) { - case NIIF_INFO: mbp->dwStyle|=MB_ICONINFORMATION; break; - case NIIF_WARNING: mbp->dwStyle|=MB_ICONWARNING; break; - case NIIF_ERROR: mbp->dwStyle|=MB_ICONERROR; + switch (flags&NIIF_ICON_MASK) { + case NIIF_INFO: mbp->dwStyle |= MB_ICONINFORMATION; break; + case NIIF_WARNING: mbp->dwStyle |= MB_ICONWARNING; break; + case NIIF_ERROR: mbp->dwStyle |= MB_ICONERROR; } mir_forkThread(MessageBoxIndirectFree, mbp); } @@ -181,10 +181,10 @@ void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...) // LocalFree() the return value char* GetWinErrorDescription(DWORD dwLastError) { - char *buf=nullptr; + char *buf = nullptr; DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM; - if (!FormatMessageA(flags,nullptr,dwLastError, LANGIDFROMLCID(Langpack_GetDefaultLocale()),(char*)&buf,0,nullptr)) - if(GetLastError()==ERROR_RESOURCE_LANG_NOT_FOUND) - FormatMessageA(flags,nullptr,dwLastError,0,(char*)&buf,0,nullptr); + if (!FormatMessageA(flags, nullptr, dwLastError, LANGIDFROMLCID(Langpack_GetDefaultLocale()), (char*)&buf, 0, nullptr)) + if (GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND) + FormatMessageA(flags, nullptr, dwLastError, 0, (char*)&buf, 0, nullptr); return buf; } -- cgit v1.2.3