From bf95ecabe893a0dac65d4906df3ff2ebf0e5a0ca Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 24 Apr 2019 15:24:11 +0300 Subject: fixes #1923 (ShellExt doesn't work in Windows 64) --- plugins/ShellExt/src/main.cpp | 118 ++++++++++++++++++++++++++++-------- plugins/ShellExt/src/options.cpp | 32 +++++----- plugins/ShellExt/src/shlcom.cpp | 54 ++++++++--------- plugins/ShellExt/src/shlcom.h | 99 ++++++++++++++++-------------- plugins/ShellExt/src/shlext.cpp | 118 ++++++++++++++++++------------------ plugins/ShellExt/src/shlfactory.cpp | 18 +++--- plugins/ShellExt/src/shlicons.cpp | 6 +- plugins/ShellExt/src/shlipc.cpp | 14 ++--- plugins/ShellExt/src/stdafx.h | 2 +- plugins/ShellExt/src/utils.cpp | 8 +-- plugins/ShellExt/src/version.h | 2 +- 11 files changed, 272 insertions(+), 199 deletions(-) (limited to 'plugins/ShellExt/src') diff --git a/plugins/ShellExt/src/main.cpp b/plugins/ShellExt/src/main.cpp index dbd3f93c4c..0de062e3fa 100644 --- a/plugins/ShellExt/src/main.cpp +++ b/plugins/ShellExt/src/main.cpp @@ -8,13 +8,77 @@ bool bIsVistaPlus; BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID) { if (fdwReason == DLL_PROCESS_ATTACH) { - bIsVistaPlus = GetProcAddress( GetModuleHandleA("kernel32.dll"), "GetProductInfo") != nullptr; + bIsVistaPlus = GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetProductInfo") != 0; DisableThreadLibraryCalls(hinstDLL); } return TRUE; } +#ifdef _WIN64 +#define MIRANDA_PROCESS L"miranda64.exe" +#else +#define MIRANDA_PROCESS L"miranda32.exe" +#endif + +#include +#pragma comment(lib, "delayimp.lib") + +static bool bModuleInited = false; + +static wchar_t* FindSlash(wchar_t *str) +{ + for (wchar_t *p = str + lstrlenW(str); p >= str; p--) + if (*p == '\\') + return p; + + return nullptr; +} + +static bool GetMirandaPath(wchar_t * wszPath) +{ + DWORD dwSize = MAX_PATH; + return (0 == RegGetValueW(HKEY_CLASSES_ROOT, L"CLSID\\{72013A26-A94C-11d6-8540-A5E62932711D}\\InprocServer32", 0, RRF_RT_REG_SZ, 0, wszPath, &dwSize)); +} + +EXTERN_C HANDLE WINAPI hook(unsigned mode, PDelayLoadInfo) +{ + if (mode == dliNotePreLoadLibrary && !bModuleInited) { + wchar_t wszPath[MAX_PATH]; + GetModuleFileNameW(nullptr, wszPath, _countof(wszPath)); + + wchar_t* p = FindSlash(wszPath); + if (p != nullptr) { + // if we're launched from miranda, do nothing + if (!lstrcmpiW(p+1, MIRANDA_PROCESS)) + return 0; + + *p = 0; + } + + if (!GetMirandaPath(wszPath)) return 0; + if (!(p = FindSlash(wszPath))) return 0; // fall back to Plugins + *p = 0; + if (!(p = FindSlash(wszPath))) return 0; // fall back to miranda's root directory + *p = 0; + + lstrcatW(wszPath, L"\\libs"); + SetDllDirectoryW(wszPath); + + #ifdef _DEBUG + lstrcatW(wszPath, L"\\ucrtbased.dll"); + #else + lstrcatW(wszPath, L"\\ucrtbase.dll"); + #endif + LoadLibraryW(wszPath); + bModuleInited = true; + } + + return 0; +} + +EXTERN_C const PfnDliHook __pfnDliNotifyHook2 = (PfnDliHook)&hook; + ///////////////////////////////////////////////////////////////////////////////////////// PLUGININFOEX pluginInfoEx = { @@ -32,19 +96,20 @@ PLUGININFOEX pluginInfoEx = { CMPlugin::CMPlugin() : PLUGIN("shlext15", pluginInfoEx) -{} +{ +} ///////////////////////////////////////////////////////////////////////////////////////// // exported functions -const IID CLSID_ISHLCOM = { 0x72013A26, 0xA94C, 0x11d6, {0x85, 0x40, 0xA5, 0xE6, 0x29, 0x32, 0x71, 0x1D }}; +const IID CLSID_ISHLCOM = { 0x72013A26, 0xA94C, 0x11d6, {0x85, 0x40, 0xA5, 0xE6, 0x29, 0x32, 0x71, 0x1D } }; STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { if (rclsid == CLSID_ISHLCOM) { - TClassFactoryRec *p = new TClassFactoryRec(); + TClassFactoryRec* p = new TClassFactoryRec(); HRESULT hr = p->QueryInterface(riid, ppv); - if ( FAILED(hr)) { + if (FAILED(hr)) { delete p; return hr; } @@ -52,14 +117,14 @@ STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) return S_OK; } - #ifdef LOG_ENABLED - RPC_CSTR szGuid; - UuidToStringA(&riid, &szGuid); - logA("DllGetClassObject {%08x-%04x-%04x-%08x%08x} failed\n", szGuid); - RpcStringFreeA(&szGuid); - #endif +#ifdef LOG_ENABLED + RPC_CSTR szGuid; + UuidToStringA(&riid, &szGuid); + logA("DllGetClassObject {%08x-%04x-%04x-%08x%08x} failed\n", szGuid); + RpcStringFreeA(&szGuid); +#endif - *ppv = nullptr; + * ppv = nullptr; return CLASS_E_CLASSNOTAVAILABLE; } @@ -75,12 +140,13 @@ STDAPI DllCanUnloadNow() struct HRegKey { - HRegKey(HKEY hRoot, const wchar_t *ptszKey) : m_key(nullptr) - { RegCreateKeyEx(hRoot, ptszKey, 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, nullptr, &m_key, nullptr); + HRegKey(HKEY hRoot, const wchar_t* ptszKey) : m_key(nullptr) + { + RegCreateKeyEx(hRoot, ptszKey, 0, nullptr, 0, KEY_SET_VALUE | KEY_CREATE_SUB_KEY, nullptr, &m_key, nullptr); } - + ~HRegKey() { if (m_key) RegCloseKey(m_key); } - + operator HKEY() const { return m_key; } private: @@ -91,7 +157,7 @@ char str1[100]; char str2[] = "{72013A26-A94C-11d6-8540-A5E62932711D}"; char str3[] = "miranda.shlext"; char str4[] = "Apartment"; - + STDAPI DllRegisterServer() { HRegKey k1(HKEY_CLASSES_ROOT, L"miranda.shlext"); @@ -99,9 +165,9 @@ STDAPI DllRegisterServer() return E_FAIL; int str1len = sprintf_s(str1, sizeof(str1), "shlext %d.%d.%d.%d - shell context menu support for Miranda NG", __FILEVERSION_STRING); - if ( RegSetValueA(k1, nullptr, REG_SZ, str1, str1len)) + if (RegSetValueA(k1, nullptr, REG_SZ, str1, str1len)) return E_FAIL; - if ( RegSetValueA(k1, "CLSID", REG_SZ, str2, sizeof(str2))) + if (RegSetValueA(k1, "CLSID", REG_SZ, str2, sizeof(str2))) return E_FAIL; ////////////////////////////////////////////////////////////////////////////////////// @@ -110,9 +176,9 @@ STDAPI DllRegisterServer() if (kClsid == nullptr) return E_FAIL; - if ( RegSetValueA(kClsid, nullptr, REG_SZ, str3, sizeof(str3))) + if (RegSetValueA(kClsid, nullptr, REG_SZ, str3, sizeof(str3))) return E_FAIL; - if ( RegSetValueA(kClsid, "ProgID", REG_SZ, str3, sizeof(str3))) + if (RegSetValueA(kClsid, "ProgID", REG_SZ, str3, sizeof(str3))) return E_FAIL; HRegKey kInprocServer(kClsid, L"InprocServer32"); @@ -121,16 +187,16 @@ STDAPI DllRegisterServer() wchar_t tszFileName[MAX_PATH]; GetModuleFileName(g_plugin.getInst(), tszFileName, _countof(tszFileName)); - if ( RegSetValueEx(kInprocServer, nullptr, 0, REG_SZ, (LPBYTE)tszFileName, sizeof(wchar_t)*(lstrlen(tszFileName)+1))) + if (RegSetValueEx(kInprocServer, nullptr, 0, REG_SZ, (LPBYTE)tszFileName, sizeof(wchar_t) * (lstrlen(tszFileName) + 1))) return E_FAIL; - if ( RegSetValueExA(kInprocServer, "ThreadingModel", 0, REG_SZ, (PBYTE)str4, sizeof(str4))) + if (RegSetValueExA(kInprocServer, "ThreadingModel", 0, REG_SZ, (PBYTE)str4, sizeof(str4))) return E_FAIL; ////////////////////////////////////////////////////////////////////////////////////// - if ( RegSetValueA(HKEY_CLASSES_ROOT, "*\\shellex\\ContextMenuHandlers\\miranda.shlext", REG_SZ, str2, sizeof(str2))) + if (RegSetValueA(HKEY_CLASSES_ROOT, "*\\shellex\\ContextMenuHandlers\\miranda.shlext", REG_SZ, str2, sizeof(str2))) return E_FAIL; - if ( RegSetValueA(HKEY_CLASSES_ROOT, "Directory\\shellex\\ContextMenuHandlers\\miranda.shlext", REG_SZ, str2, sizeof(str2))) + if (RegSetValueA(HKEY_CLASSES_ROOT, "Directory\\shellex\\ContextMenuHandlers\\miranda.shlext", REG_SZ, str2, sizeof(str2))) return E_FAIL; ////////////////////////////////////////////////////////////////////////////////////// @@ -138,7 +204,7 @@ STDAPI DllRegisterServer() HRegKey k2(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"); if (k2 == nullptr) return E_FAIL; - if ( RegSetValueExA(k2, str2, 0, REG_SZ, (PBYTE)str1, str1len)) + if (RegSetValueExA(k2, str2, 0, REG_SZ, (PBYTE)str1, str1len)) return E_FAIL; return S_OK; diff --git a/plugins/ShellExt/src/options.cpp b/plugins/ShellExt/src/options.cpp index 0933b708fc..01b9b098fb 100644 --- a/plugins/ShellExt/src/options.cpp +++ b/plugins/ShellExt/src/options.cpp @@ -3,19 +3,19 @@ static void AutoSize(HWND hwnd) { - HDC hDC = GetDC(hwnd); - HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); - HFONT hOldFont = (HFONT)SelectObject(hDC, hFont); - - wchar_t szBuf[MAX_PATH]; - int i = GetWindowText(hwnd, szBuf, _countof(szBuf)); - - SIZE tS; - GetTextExtentPoint32(hDC, szBuf, i, &tS); - SelectObject(hDC, hOldFont); - DeleteObject(hFont); - ReleaseDC(hwnd, hDC); - SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, tS.cx + 10, tS.cy, SWP_NOMOVE | SWP_FRAMECHANGED); + HDC hDC = GetDC(hwnd); + HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); + HFONT hOldFont = (HFONT)SelectObject(hDC, hFont); + + wchar_t szBuf[MAX_PATH]; + int i = GetWindowText(hwnd, szBuf, _countof(szBuf)); + + SIZE tS; + GetTextExtentPoint32(hDC, szBuf, i, &tS); + SelectObject(hDC, hOldFont); + DeleteObject(hFont); + ReleaseDC(hwnd, hDC); + SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, tS.cx + 10, tS.cy, SWP_NOMOVE | SWP_FRAMECHANGED); } //////////////////////////////////////////////////////////////////////////////////////////// @@ -34,13 +34,13 @@ static void InitControls(HWND hwndDlg) TranslateW(COM_OKSTR[(comReg & COMREG_OK) != 0]), TranslateW(COM_APPROVEDSTR[(comReg & COMREG_APPROVED) != 0])); SetDlgItemText(hwndDlg, IDC_STATUS, szBuf); - + // auto size the static windows to fit their text // they're rendering in a font not selected into the DC. AutoSize(GetDlgItem(hwndDlg, IDC_CAPMENUS)); AutoSize(GetDlgItem(hwndDlg, IDC_CAPSTATUS)); AutoSize(GetDlgItem(hwndDlg, IDC_CAPSHLSTATUS)); - + // show all the options int iCheck = g_plugin.getByte(SHLExt_UseGroups, BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_USEGROUPS, iCheck ? BST_CHECKED : BST_UNCHECKED); @@ -51,7 +51,7 @@ static void InitControls(HWND hwndDlg) CheckDlgButton(hwndDlg, IDC_SHOWINVISIBLES, g_plugin.getByte(SHLExt_UseHIT2Contacts, BST_UNCHECKED)); CheckDlgButton(hwndDlg, IDC_USEOWNERDRAW, g_plugin.getByte(SHLExt_ShowNoIcons, BST_UNCHECKED)); CheckDlgButton(hwndDlg, IDC_HIDEOFFLINE, g_plugin.getByte(SHLExt_ShowNoOffline, BST_UNCHECKED)); - + // give the Remove button a Vista icon SendDlgItemMessage(hwndDlg, IDC_REMOVE, BCM_SETSHIELD, 0, 1); } diff --git a/plugins/ShellExt/src/shlcom.cpp b/plugins/ShellExt/src/shlcom.cpp index 2bcc909aaf..3b13388e9f 100644 --- a/plugins/ShellExt/src/shlcom.cpp +++ b/plugins/ShellExt/src/shlcom.cpp @@ -11,9 +11,9 @@ struct TCMInvokeCommandInfo int cbSize; DWORD fMask; HWND hwnd; - char *lpVerb; // maybe index, type cast as Integer - char *lpParams; - char *lpDir; + char* lpVerb; // maybe index, type cast as Integer + char* lpParams; + char* lpDir; int nShow; DWORD dwHotkey; HICON hIcon; @@ -44,7 +44,7 @@ int IsCOMRegistered() ///////////////////////////////////////////////////////////////////////////////////////// -char* CreateProcessUID(int pid, char *buf, size_t bufLen) +char* CreateProcessUID(int pid, char* buf, size_t bufLen) { sprintf_s(buf, bufLen, "mim.shlext.%d$", pid); return buf; @@ -61,7 +61,7 @@ struct TAddArgList LPSTR szFile; // file being processed int cch; // it's length (with space for NULL char) int count; // number we have so far - LPSTR *files; + LPSTR* files; MCONTACT hContact; HANDLE hEvent; }; @@ -81,7 +81,7 @@ BOOL AddToList(TAddArgList& args) // add the directory lstrcpyA(szBuf, args.szFile); args.files = (LPSTR*)mir_realloc(args.files, (args.count + 1) * sizeof(LPSTR)); - char *p = mir_strdup(szBuf); + char* p = mir_strdup(szBuf); args.files[args.count++] = p; // tack on ending search token lstrcatA(szBuf, "\\*"); @@ -122,13 +122,13 @@ BOOL AddToList(TAddArgList& args) void NTAPI MainThreadIssueTransfer(ULONG_PTR param) { - TAddArgList *p = (TAddArgList *)param; + TAddArgList* p = (TAddArgList*)param; g_plugin.setByte(p->hContact, SHLExt_MRU, 1); CallService(MS_FILE_SENDSPECIFICFILES, (WPARAM)p->hContact, LPARAM(p->files)); SetEvent(p->hEvent); } -void __cdecl IssueTransferThread(THeaderIPC *pipch) +void __cdecl IssueTransferThread(THeaderIPC * pipch) { HANDLE hMainThread = HANDLE(pipch->Param); @@ -138,7 +138,7 @@ void __cdecl IssueTransferThread(THeaderIPC *pipch) TAddArgList args; args.count = 0; args.files = nullptr; - TSlotIPC *pct = pipch->DataPtr; + TSlotIPC* pct = pipch->DataPtr; BOOL bQuit = false; while (pct != nullptr) { if (pct->cbSize != sizeof(TSlotIPC)) @@ -180,28 +180,28 @@ struct TSlotInfo int dwStatus; // will be aligned anyway }; -int __cdecl SortContact(const void *Item1, const void *Item2) +int __cdecl SortContact(const void* Item1, const void* Item2) { return Clist_ContactCompare(((TSlotInfo*)Item1)->hContact, ((TSlotInfo*)Item2)->hContact); } -void ipcGetSkinIcons(THeaderIPC *ipch) +void ipcGetSkinIcons(THeaderIPC * ipch) { TSlotProtoIcons spi; char szTmp[64]; int protoCount; - PROTOACCOUNT **pp; + PROTOACCOUNT** pp; Proto_EnumAccounts(&protoCount, &pp); if (protoCount != 0) { spi.pid = GetCurrentProcessId(); while (protoCount > 0) { - PROTOACCOUNT *pa = *pp; + PROTOACCOUNT* pa = *pp; lstrcpyA(szTmp, pa->szModuleName); lstrcatA(szTmp, PS_GETCAPS); DWORD dwCaps = CallService(szTmp, PFLAGNUM_1, 0); if (dwCaps & PF1_FILESEND) { - TSlotIPC *pct = ipcAlloc(ipch, sizeof(TSlotProtoIcons)); + TSlotIPC* pct = ipcAlloc(ipch, sizeof(TSlotProtoIcons)); if (pct != nullptr) { // capture all the icons! spi.hProto = murmur_hash(pa->szModuleName); @@ -220,7 +220,7 @@ void ipcGetSkinIcons(THeaderIPC *ipch) } // add Miranda icon - TSlotIPC *pct = ipcAlloc(ipch, sizeof(TSlotProtoIcons)); + TSlotIPC* pct = ipcAlloc(ipch, sizeof(TSlotProtoIcons)); if (pct != nullptr) { memset(&spi.hIcons, 0, sizeof(spi.hIcons)); spi.hProto = 0; // no protocol @@ -232,7 +232,7 @@ void ipcGetSkinIcons(THeaderIPC *ipch) } } -bool ipcGetSortedContacts(THeaderIPC *ipch, int *pSlot, bool bGroupMode) +bool ipcGetSortedContacts(THeaderIPC * ipch, int* pSlot, bool bGroupMode) { // hide offliners? bool bHideOffline = db_get_b(0, "CList", "HideOffline", 0) == 1; @@ -248,15 +248,15 @@ bool ipcGetSortedContacts(THeaderIPC *ipch, int *pSlot, bool bGroupMode) // get the contacts in the array to be sorted by status, trim out anyone // who doesn't wanna be seen. - TSlotInfo *pContacts = (TSlotInfo*)mir_alloc((dwContacts + 2) * sizeof(TSlotInfo)); + TSlotInfo * pContacts = (TSlotInfo*)mir_alloc((dwContacts + 2) * sizeof(TSlotInfo)); int i = 0; int dwOnline = 0; - for (auto &hContact : Contacts()) { + for (auto& hContact : Contacts()) { if (i >= dwContacts) break; // do they have a running protocol? - char *szProto = GetContactProto(hContact); + char* szProto = GetContactProto(hContact); if (szProto != nullptr) { // does it support file sends? DWORD dwCaps = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0); @@ -307,7 +307,7 @@ bool ipcGetSortedContacts(THeaderIPC *ipch, int *pSlot, bool bGroupMode) szGroup = db_get_sa(pContacts[i].hContact, "CList", "Group"); int cch = lstrlenA(szContact) + 1; - TSlotIPC *pct = ipcAlloc(ipch, cch + 1 + lstrlenA(szGroup) + 1); + TSlotIPC* pct = ipcAlloc(ipch, cch + 1 + lstrlenA(szGroup) + 1); if (pct == nullptr) break; @@ -341,7 +341,7 @@ bool ipcGetSortedContacts(THeaderIPC *ipch, int *pSlot, bool bGroupMode) // worker thread to clear MRU, called by the IPC bridge void __cdecl ClearMRUThread(void*) { - for (auto &hContact : Contacts()) + for (auto& hContact : Contacts()) if (g_plugin.getBool(hContact, SHLExt_MRU)) g_plugin.setByte(hContact, SHLExt_MRU, false); } @@ -362,14 +362,14 @@ void __stdcall ipcService(ULONG_PTR) return; // map the file to this process - THeaderIPC *pMMT = (THeaderIPC*)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); + THeaderIPC * pMMT = (THeaderIPC*)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); // if it fails the caller should of had some timeout in wait if (pMMT != nullptr && pMMT->cbSize == sizeof(THeaderIPC) && pMMT->dwVersion == PLUGIN_MAKE_VERSION(2, 0, 1, 2)) { // toggle the right bits - int *bits = &pMMT->fRequests; + int* bits = &pMMT->fRequests; // jump right to a worker thread for file processing? if (*bits & REQUEST_XFRFILES) { - THeaderIPC *cloned = (THeaderIPC*)mir_alloc(IPC_PACKET_SIZE); + THeaderIPC* cloned = (THeaderIPC*)mir_alloc(IPC_PACKET_SIZE); // translate from client space to cloned heap memory pMMT->pServerBaseAddress = pMMT->pClientBaseAddress; pMMT->pClientBaseAddress = cloned; @@ -416,7 +416,7 @@ void __stdcall ipcService(ULONG_PTR) if (bGroupMode && BST_CHECKED == g_plugin.getByte(SHLExt_UseCListSetting, BST_UNCHECKED)) bGroupMode = db_get_b(0, "CList", "UseGroups", true) != 0; - TSlotIPC *pct = nullptr; + TSlotIPC * pct = nullptr; int iSlot = 0; // return profile if set if (BST_UNCHECKED == g_plugin.getByte(SHLExt_ShowNoProfile, BST_UNCHECKED)) { @@ -457,13 +457,13 @@ void __stdcall ipcService(ULONG_PTR) } // if there was no space left, it'll } on null if (pct == nullptr) - *bits = (*bits | GROUPS_NOTIMPL) & ~REQUEST_GROUPS; + * bits = (*bits | GROUPS_NOTIMPL) & ~REQUEST_GROUPS; } // SHOULD check slot space. if (*bits & REQUEST_CONTACTS) { if (!ipcGetSortedContacts(pMMT, &iSlot, bGroupMode)) // fail if there were no contacts AT ALL - *bits = (*bits | CONTACTS_NOTIMPL) & ~REQUEST_CONTACTS; + * bits = (*bits | CONTACTS_NOTIMPL) & ~REQUEST_CONTACTS; } // store the number of slots allocated pMMT->Slots = iSlot; diff --git a/plugins/ShellExt/src/shlcom.h b/plugins/ShellExt/src/shlcom.h index 21f0a87927..f96465db96 100644 --- a/plugins/ShellExt/src/shlcom.h +++ b/plugins/ShellExt/src/shlcom.h @@ -48,24 +48,24 @@ struct TGroupNode { - TGroupNode *Left, *Right, *_prev, *_next; + TGroupNode* Left, * Right, * _prev, * _next; int Depth; - UINT Hash; // hash of the group name alone - char *szGroup; - int cchGroup; - HMENU hMenu; - int hMenuGroupID; - DWORD dwItems; + UINT Hash; // hash of the group name alone + char* szGroup; + int cchGroup; + HMENU hMenu; + int hMenuGroupID; + DWORD dwItems; }; struct TGroupNodeList { - TGroupNode *First, *Last; + TGroupNode* First, * Last; }; struct TStrTokRec { - char *szStr, *szSet; + char* szStr, * szSet; // need a delimiter after the token too?, e.g. FOO^BAR^ if FOO^BAR // is the string then only FOO^ is returned, could cause infinite loops // if the condition isn't accounted for thou. @@ -86,21 +86,21 @@ struct TSlotIPC { BYTE cbSize; int fType; // a REQUEST_* type - TSlotIPC *Next; + TSlotIPC* Next; MCONTACT hContact; UINT hProto; // hash of the protocol the user is on UINT hGroup; // hash of the entire path (not defined for REQUEST_GROUPS slots) WORD Status; // only used for contacts -- can be STATUS_PROFILENAME -- but that is because returning the profile name is optional - BYTE MRU; // if set, contact has been recently used - int cbStrSection; + BYTE MRU; // if set, contact has been recently used + int cbStrSection; }; struct THeaderIPC { int cbSize; DWORD dwVersion; - void *pServerBaseAddress, *pClientBaseAddress; + void* pServerBaseAddress, * pClientBaseAddress; int fRequests; DWORD dwFlags; int Slots; @@ -109,11 +109,11 @@ struct THeaderIPC char MirandaName[64]; char MRUMenuName[64]; char ClearEntries[64]; - TSlotIPC *IconsBegin, *ContactsBegin, *GroupsBegin, *NewIconsBegin; + TSlotIPC* IconsBegin, * ContactsBegin, * GroupsBegin, * NewIconsBegin; // start of an flat memory stack, which is referenced as a linked list int DataSize; - TSlotIPC *DataPtr, *DataPtrEnd; - void *DataFramePtr; + TSlotIPC* DataPtr, * DataPtrEnd; + void* DataFramePtr; }; ///////////////////////////////////////////////////////////////////////////////////////// @@ -138,40 +138,40 @@ struct TShellExt : public IShellExtInit, public IContextMenu3, public MZeroedObj HMENU hRecentMenu; UINT RecentCount; // number of added items // array of all the protocol icons, for every running instance! - TSlotProtoIcons *ProtoIcons; + TSlotProtoIcons* ProtoIcons; UINT ProtoIconsCount; // maybe null, taken from IShellExtInit_Initalise() and AddRef()'d // only used if a Miranda instance is actually running and a user // is selected - IDataObject *pDataObject; + IDataObject* pDataObject; // DC is used for font metrics and saves on creating and destroying lots of DC handles // during WM_MEASUREITEM HDC hMemDC; - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); ULONG STDMETHODCALLTYPE AddRef(void); ULONG STDMETHODCALLTYPE Release(void); - HRESULT STDMETHODCALLTYPE Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID); + HRESULT STDMETHODCALLTYPE Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID); HRESULT STDMETHODCALLTYPE QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags); - HRESULT STDMETHODCALLTYPE InvokeCommand(CMINVOKECOMMANDINFO *pici); - HRESULT STDMETHODCALLTYPE GetCommandString(UINT_PTR idCmd, UINT uType, UINT *pReserved, LPSTR pszName, UINT cchMax); + HRESULT STDMETHODCALLTYPE InvokeCommand(CMINVOKECOMMANDINFO* pici); + HRESULT STDMETHODCALLTYPE GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pReserved, LPSTR pszName, UINT cchMax); HRESULT STDMETHODCALLTYPE HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam); - HRESULT STDMETHODCALLTYPE HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult); + HRESULT STDMETHODCALLTYPE HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plResult); }; struct TEnumData { - TShellExt *Self; + TShellExt* Self; - // autodetected, don't hard code since shells that don't support it - // won't send WM_MEASUREITETM/WM_DRAWITEM at all. + // autodetected, don't hard code since shells that don't support it + // won't send WM_MEASUREITETM/WM_DRAWITEM at all. BOOL bOwnerDrawSupported; // as per user setting (maybe of multiple Mirandas) BOOL bShouldOwnerDraw; int idCmdFirst; - THeaderIPC *ipch; + THeaderIPC* ipch; // OpenEvent()'d handle to give each IPC server an object to set signalled HANDLE hWaitFor; DWORD pid; // sub-unique value used to make work object name @@ -183,45 +183,52 @@ struct TClassFactoryRec : public IClassFactory LONG RefCount; - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); ULONG STDMETHODCALLTYPE AddRef(void); ULONG STDMETHODCALLTYPE Release(void); - HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject); + HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppvObject); HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock); }; ///////////////////////////////////////////////////////////////////////////////////////// -enum TSlotDrawType {dtEntry = 0x01, dtGroup = 0x02, dtContact = 0x04, dtCommand = 0x08 }; +enum TSlotDrawType +{ + dtEntry = 0x01, + dtGroup = 0x02, + dtContact = 0x04, + dtCommand = 0x08 +}; + typedef int TSlotDrawTypes; -typedef int (__stdcall TMenuCommandCallback)( - THeaderIPC *pipch, // IPC header info, already mapped - HANDLE hWorkThreadEvent, // event object being waited on on miranda thread - HANDLE hAckEvent); // ack event object that has been created +typedef int(__stdcall TMenuCommandCallback)( + THeaderIPC* pipch, // IPC header info, already mapped + HANDLE hWorkThreadEvent, // event object being waited on on miranda thread + HANDLE hAckEvent); // ack event object that has been created struct TMenuDrawInfo { - char *szText, *szProfile; + char* szText, * szProfile; int cch; UINT wID; - TSlotDrawTypes fTypes; - MCONTACT hContact; + TSlotDrawTypes fTypes; + MCONTACT hContact; HICON hStatusIcon; // HICON from Self->ProtoIcons[index].hIcons[status]; Do not DestroyIcon() - HBITMAP hStatusBitmap; // HBITMAP, don't free. - int pid; - TMenuCommandCallback *MenuCommandCallback; // dtCommand must be set also. + HBITMAP hStatusBitmap; // HBITMAP, don't free. + int pid; + TMenuCommandCallback* MenuCommandCallback; // dtCommand must be set also. }; ///////////////////////////////////////////////////////////////////////////////////////// -void ipcPrepareRequests(int ipcPacketSize, THeaderIPC *pipch, DWORD fRequests); -DWORD ipcSendRequest(HANDLE hSignal, HANDLE hWaitFor, THeaderIPC *pipch, DWORD dwTimeoutMsecs); -TSlotIPC* ipcAlloc(THeaderIPC *pipch, int nSize); -void ipcFixupAddresses(THeaderIPC *pipch); +void ipcPrepareRequests(int ipcPacketSize, THeaderIPC* pipch, DWORD fRequests); +DWORD ipcSendRequest(HANDLE hSignal, HANDLE hWaitFor, THeaderIPC* pipch, DWORD dwTimeoutMsecs); +TSlotIPC* ipcAlloc(THeaderIPC* pipch, int nSize); +void ipcFixupAddresses(THeaderIPC* pipch); -TGroupNode* AllocGroupNode(TGroupNodeList *list, TGroupNode *Root, int Depth); +TGroupNode* AllocGroupNode(TGroupNodeList* list, TGroupNode* Root, int Depth); TGroupNode* FindGroupNode(TGroupNode* p, const DWORD Hash, int Depth); -char* CreateProcessUID(int pid, char *buf, size_t bufLen); +char* CreateProcessUID(int pid, char* buf, size_t bufLen); diff --git a/plugins/ShellExt/src/shlext.cpp b/plugins/ShellExt/src/shlext.cpp index 9d887b03e2..20036fb699 100644 --- a/plugins/ShellExt/src/shlext.cpp +++ b/plugins/ShellExt/src/shlext.cpp @@ -2,7 +2,7 @@ #include "shlcom.h" #include "shlicons.h" -static char* CreateUID(char *buf, size_t bufLen) +static char* CreateUID(char* buf, size_t bufLen) { sprintf_s(buf, bufLen, "'mim.shlext.caller%d$%d", GetCurrentProcessId(), GetCurrentThreadId()); return buf; @@ -30,7 +30,7 @@ TShellExt::~TShellExt() ULONG c = ProtoIconsCount; while (c > 0) { c--; - TSlotProtoIcons *p = &ProtoIcons[c]; + TSlotProtoIcons* p = &ProtoIcons[c]; for (int j = 0; j < 10; j++) { if (p->hIcons[j] != nullptr) DestroyIcon(p->hIcons[j]); @@ -53,7 +53,7 @@ TShellExt::~TShellExt() DeleteDC(hMemDC); } -HRESULT TShellExt::QueryInterface(REFIID riid, void **ppvObject) +HRESULT TShellExt::QueryInterface(REFIID riid, void** ppvObject) { if (ppvObject == nullptr) return E_POINTER; @@ -76,12 +76,12 @@ HRESULT TShellExt::QueryInterface(REFIID riid, void **ppvObject) } else { *ppvObject = nullptr; - #ifdef LOG_ENABLED - RPC_CSTR szGuid; - UuidToStringA(&riid, &szGuid); - logA("TShellExt[%p] failed as {%s}\n", this, szGuid); - RpcStringFreeA(&szGuid); - #endif + #ifdef LOG_ENABLED + RPC_CSTR szGuid; + UuidToStringA(&riid, &szGuid); + logA("TShellExt[%p] failed as {%s}\n", this, szGuid); + RpcStringFreeA(&szGuid); + #endif return E_NOINTERFACE; } @@ -104,13 +104,13 @@ ULONG TShellExt::Release() logA("TShellExt[%p] final release\n", this); delete this; DllObjectCount--; - } + } else logA("TShellExt[%p] release ref: %d\n", this, RefCount); return ret; } -HRESULT TShellExt::Initialize(PCIDLIST_ABSOLUTE, IDataObject *pdtobj, HKEY) +HRESULT TShellExt::Initialize(PCIDLIST_ABSOLUTE, IDataObject * pdtobj, HKEY) { // DObj is a pointer to an instance of IDataObject which is a pointer itself // it contains a pointer to a function table containing the function pointer @@ -136,10 +136,10 @@ HRESULT TShellExt::GetCommandString(UINT_PTR, UINT, UINT*, LPSTR, UINT) ///////////////////////////////////////////////////////////////////////////////////////// -void FreeGroupTreeAndEmptyGroups(HMENU hParentMenu, TGroupNode *pp, TGroupNode *p) +void FreeGroupTreeAndEmptyGroups(HMENU hParentMenu, TGroupNode * pp, TGroupNode * p) { while (p != nullptr) { - TGroupNode *q = p->Right; + TGroupNode* q = p->Right; if (p->Left != nullptr) FreeGroupTreeAndEmptyGroups(p->Left->hMenu, p, p->Left); @@ -159,13 +159,13 @@ void FreeGroupTreeAndEmptyGroups(HMENU hParentMenu, TGroupNode *pp, TGroupNode * } } -void DecideMenuItemInfo(TSlotIPC *pct, TGroupNode *pg, MENUITEMINFOA &mii, TEnumData *lParam) +void DecideMenuItemInfo(TSlotIPC * pct, TGroupNode * pg, MENUITEMINFOA & mii, TEnumData * lParam) { mii.wID = lParam->idCmdFirst; lParam->idCmdFirst++; // get the heap object HANDLE hDllHeap = lParam->Self->hDllHeap; - TMenuDrawInfo *psd = (TMenuDrawInfo*)HeapAlloc(hDllHeap, 0, sizeof(TMenuDrawInfo)); + TMenuDrawInfo* psd = (TMenuDrawInfo*)HeapAlloc(hDllHeap, 0, sizeof(TMenuDrawInfo)); if (pct != nullptr) { psd->cch = pct->cbStrSection - 1; // no null; psd->szText = (char*)HeapAlloc(hDllHeap, 0, pct->cbStrSection); @@ -174,7 +174,7 @@ void DecideMenuItemInfo(TSlotIPC *pct, TGroupNode *pg, MENUITEMINFOA &mii, TEnum psd->fTypes = dtContact; // find the protocol icon array to use && which status UINT c = lParam->Self->ProtoIconsCount; - TSlotProtoIcons *pp = lParam->Self->ProtoIcons; + TSlotProtoIcons * pp = lParam->Self->ProtoIcons; psd->hStatusIcon = nullptr; while (c > 0) { c--; @@ -224,7 +224,7 @@ void DecideMenuItemInfo(TSlotIPC *pct, TGroupNode *pg, MENUITEMINFOA &mii, TEnum // this callback is triggered by the menu code and IPC is already taking place, // just the transfer type+data needs to be setup int __stdcall ClearMRUIPC( - THeaderIPC *pipch, // IPC header info, already mapped + THeaderIPC * pipch, // IPC header info, already mapped HANDLE hWorkThreadEvent, // event object being waited on on miranda thread HANDLE hAckEvent) // ack event object that has been created { @@ -246,7 +246,7 @@ void RemoveCheckmarkSpace(HMENU HMENU) } // must be called after DecideMenuItemInfo() -void BuildMRU(TSlotIPC *pct, MENUITEMINFOA &mii, TEnumData *lParam) +void BuildMRU(TSlotIPC * pct, MENUITEMINFOA & mii, TEnumData * lParam) { if (pct->MRU > 0) { lParam->Self->RecentCount++; @@ -255,14 +255,14 @@ void BuildMRU(TSlotIPC *pct, MENUITEMINFOA &mii, TEnumData *lParam) } } -void BuildContactTree(TGroupNode *group, TEnumData *lParam) +void BuildContactTree(TGroupNode * group, TEnumData * lParam) { // set up the menu item MENUITEMINFOA mii = { sizeof(mii) }; mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA; // go thru all the contacts - TSlotIPC *pct = lParam->ipch->ContactsBegin; + TSlotIPC* pct = lParam->ipch->ContactsBegin; while (pct != nullptr && pct->cbSize == sizeof(TSlotIPC) && pct->fType == REQUEST_CONTACTS) { if (pct->hGroup != 0) { // at the } of the slot header is the contact's display name @@ -272,21 +272,21 @@ void BuildContactTree(TGroupNode *group, TEnumData *lParam) // per tokenised section, and it doesn't matter if two levels use the same group name (which is valid) // as the tokens processed is equatable to depth of the tree - char *sz = strtok(LPSTR(UINT_PTR(pct) + sizeof(TSlotIPC) + UINT_PTR(pct->cbStrSection) + 1), "\\"); + char* sz = strtok(LPSTR(UINT_PTR(pct) + sizeof(TSlotIPC) + UINT_PTR(pct->cbStrSection) + 1), "\\"); // restore the root - TGroupNode *pg = group; + TGroupNode * pg = group; int Depth = 0; while (sz != nullptr) { UINT Hash = murmur_hash(sz); // find this node within while (pg != nullptr) { // does this node have the right hash and the right depth? - if (Hash == pg->Hash && Depth == pg->Depth) + if (Hash == pg->Hash && Depth == pg->Depth) break; // each node may have a left pointer going to a sub tree // the path syntax doesn't know if a group is a group at the same level // or a nested one, which means the search node can be anywhere - TGroupNode *px = pg->Left; + TGroupNode * px = pg->Left; if (px != nullptr) { // keep searching this level while (px != nullptr) { @@ -312,12 +312,12 @@ grouploop: InsertMenuItemA(pg->hMenu, 0xFFFFFFFF, true, &mii); pg->dwItems++; } - } + } pct = pct->Next; } } -static void BuildMenuGroupTree(TGroupNode *p, TEnumData *lParam, HMENU hLastMenu) +static void BuildMenuGroupTree(TGroupNode * p, TEnumData * lParam, HMENU hLastMenu) { MENUITEMINFOA mii = { 0 }; mii.cbSize = sizeof(mii); @@ -335,29 +335,29 @@ static void BuildMenuGroupTree(TGroupNode *p, TEnumData *lParam, HMENU hLastMenu } } -static void BuildMenus(TEnumData *lParam) +static void BuildMenus(TEnumData * lParam) { LPSTR Token; - TMenuDrawInfo *psd; + TMenuDrawInfo* psd; HANDLE hDllHeap = lParam->Self->hDllHeap; HMENU hBaseMenu = lParam->Self->hRootMenu; // build an in memory tree of the groups TGroupNodeList j = { nullptr, nullptr }; - TSlotIPC *pg = lParam->ipch->GroupsBegin; + TSlotIPC* pg = lParam->ipch->GroupsBegin; while (pg != nullptr) { - if (pg->cbSize != sizeof(TSlotIPC) || pg->fType != REQUEST_GROUPS) + if (pg->cbSize != sizeof(TSlotIPC) || pg->fType != REQUEST_GROUPS) break; UINT Depth = 0; - TGroupNode *p = j.First; // start at root again + TGroupNode * p = j.First; // start at root again // get the group Token = strtok(LPSTR(pg) + sizeof(TSlotIPC), "\\"); while (Token != nullptr) { UINT Hash = murmur_hash(Token); // if the (sub)group doesn't exist, create it. - TGroupNode *q = FindGroupNode(p, Hash, Depth); + TGroupNode* q = FindGroupNode(p, Hash, Depth); if (q == nullptr) { q = AllocGroupNode(&j, p, Depth); q->Depth = Depth; @@ -396,20 +396,20 @@ static void BuildMenus(TEnumData *lParam) // add contacts that have a group somewhere BuildContactTree(j.First, lParam); } - + MENUITEMINFOA mii = { 0 }; mii.cbSize = sizeof(mii); mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA; // add all the contacts that have no group (which maybe all of them) pg = lParam->ipch->ContactsBegin; while (pg != nullptr) { - if (pg->cbSize != sizeof(TSlotIPC) || pg->fType != REQUEST_CONTACTS) + if (pg->cbSize != sizeof(TSlotIPC) || pg->fType != REQUEST_CONTACTS) break; if (pg->hGroup == 0) { DecideMenuItemInfo(pg, nullptr, mii, lParam); BuildMRU(pg, mii, lParam); InsertMenuItemA(hGroupMenu, 0xFFFFFFFF, true, &mii); - } + } pg = pg->Next; } @@ -499,7 +499,7 @@ static void BuildMenus(TEnumData *lParam) // get Miranda's icon or bitmap UINT c = lParam->Self->ProtoIconsCount; - TSlotProtoIcons *pp = lParam->Self->ProtoIcons; + TSlotProtoIcons* pp = lParam->Self->ProtoIcons; while (c > 0) { c--; if (pp[c].pid == lParam->pid && pp[c].hProto == 0) { @@ -525,19 +525,19 @@ static void BuildMenus(TEnumData *lParam) FreeGroupTreeAndEmptyGroups(hGroupMenu, nullptr, j.First); } -static void BuildSkinIcons(TEnumData *lParam) +static void BuildSkinIcons(TEnumData * lParam) { - IWICImagingFactory *factory = (bIsVistaPlus) ? ARGB_GetWorker() : nullptr; + IWICImagingFactory* factory = (bIsVistaPlus) ? ARGB_GetWorker() : nullptr; - TSlotIPC *pct = lParam->ipch->NewIconsBegin; - TShellExt *Self = lParam->Self; + TSlotIPC* pct = lParam->ipch->NewIconsBegin; + TShellExt* Self = lParam->Self; while (pct != nullptr) { - if (pct->cbSize != sizeof(TSlotIPC) || pct->fType != REQUEST_NEWICONS) + if (pct->cbSize != sizeof(TSlotIPC) || pct->fType != REQUEST_NEWICONS) break; - TSlotProtoIcons *p = (TSlotProtoIcons*)(PBYTE(pct) + sizeof(TSlotIPC)); + TSlotProtoIcons * p = (TSlotProtoIcons*)(PBYTE(pct) + sizeof(TSlotIPC)); Self->ProtoIcons = (TSlotProtoIcons*)realloc(Self->ProtoIcons, (Self->ProtoIconsCount + 1) * sizeof(TSlotProtoIcons)); - TSlotProtoIcons *d = &Self->ProtoIcons[Self->ProtoIconsCount]; + TSlotProtoIcons * d = &Self->ProtoIcons[Self->ProtoIconsCount]; memmove(d, p, sizeof(TSlotProtoIcons)); // if using Vista (or later), clone all the icons into bitmaps and keep these around, @@ -547,7 +547,7 @@ static void BuildSkinIcons(TEnumData *lParam) for (int j = 0; j < 10; j++) { if (bIsVistaPlus) { d->hBitmaps[j] = ARGB_BitmapFromIcon(factory, Self->hMemDC, p->hIcons[j]); - d->hIcons[j] = nullptr; + d->hIcons[j] = nullptr; } else { d->hBitmaps[j] = nullptr; @@ -567,7 +567,7 @@ BOOL __stdcall ProcessRequest(HWND hwnd, LPARAM param) { char szBuf[MAX_PATH]; - TEnumData *lParam = (TEnumData*)param; + TEnumData* lParam = (TEnumData*)param; DWORD pid = 0; GetWindowThreadProcessId(hwnd, &pid); if (pid != 0) { @@ -578,7 +578,7 @@ BOOL __stdcall ProcessRequest(HWND hwnd, LPARAM param) HANDLE hMirandaWorkEvent = OpenEventA(EVENT_ALL_ACCESS, false, CreateProcessUID(pid, szBuf, sizeof(szBuf))); if (hMirandaWorkEvent != nullptr) { GetClassNameA(hwnd, szBuf, sizeof(szBuf)); - if ( lstrcmpA(szBuf, MIRANDACLASS) != 0) { + if (lstrcmpA(szBuf, MIRANDACLASS) != 0) { // opened but not valid. logA("ProcessRequest(%d, %p): class %s differs from %s\n", pid, hwnd, szBuf, MIRANDACLASS); CloseHandle(hMirandaWorkEvent); @@ -629,7 +629,7 @@ struct DllVersionInfo DWORD dwMajorVersion, dwMinorVersion, dwBuildNumber, dwPlatformID; }; -typedef HRESULT (__stdcall *pfnDllGetVersion)(DllVersionInfo*); +typedef HRESULT(__stdcall * pfnDllGetVersion)(DllVersionInfo*); HRESULT TShellExt::QueryContextMenu(HMENU hmenu, UINT, UINT _idCmdFirst, UINT, UINT uFlags) { @@ -638,7 +638,7 @@ HRESULT TShellExt::QueryContextMenu(HMENU hmenu, UINT, UINT _idCmdFirst, UINT, U if (((LOWORD(uFlags) & CMF_VERBSONLY) != CMF_VERBSONLY) && ((LOWORD(uFlags) & CMF_DEFAULTONLY) != CMF_DEFAULTONLY)) { bool bMF_OWNERDRAW = false; // get the shell version - pfnDllGetVersion DllGetVersionProc = (pfnDllGetVersion)GetProcAddress( GetModuleHandleA("shell32.dll"), "DllGetVersion"); + pfnDllGetVersion DllGetVersionProc = (pfnDllGetVersion)GetProcAddress(GetModuleHandleA("shell32.dll"), "DllGetVersion"); if (DllGetVersionProc != nullptr) { DllVersionInfo dvi; dvi.cbSize = sizeof(dvi); @@ -654,7 +654,7 @@ HRESULT TShellExt::QueryContextMenu(HMENU hmenu, UINT, UINT _idCmdFirst, UINT, U if (hMap != nullptr && GetLastError() != ERROR_ALREADY_EXISTS) { TEnumData ed = {}; // map the memory to this address space - THeaderIPC *pipch = (THeaderIPC*)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); + THeaderIPC* pipch = (THeaderIPC*)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (pipch != nullptr) { // let the callback have instance vars ed.Self = this; @@ -695,7 +695,7 @@ HRESULT TShellExt::QueryContextMenu(HMENU hmenu, UINT, UINT _idCmdFirst, UINT, U ///////////////////////////////////////////////////////////////////////////////////////// -HRESULT ipcGetFiles(THeaderIPC *pipch, IDataObject* pDataObject, MCONTACT hContact) +HRESULT ipcGetFiles(THeaderIPC * pipch, IDataObject * pDataObject, MCONTACT hContact) { FORMATETC fet; fet.cfFormat = CF_HDROP; @@ -716,7 +716,7 @@ HRESULT ipcGetFiles(THeaderIPC *pipch, IDataObject* pDataObject, MCONTACT hConta // get the size of the file path int cbSize = DragQueryFileA((HDROP)stgm.hGlobal, iFile, nullptr, 0); // get the buffer - TSlotIPC *pct = ipcAlloc(pipch, cbSize + 1); // including null term + TSlotIPC* pct = ipcAlloc(pipch, cbSize + 1); // including null term // allocated? if (pct == nullptr) break; @@ -735,17 +735,17 @@ HRESULT ipcGetFiles(THeaderIPC *pipch, IDataObject* pDataObject, MCONTACT hConta return hr; } -HRESULT RequestTransfer(TShellExt *Self, int idxCmd) +HRESULT RequestTransfer(TShellExt * Self, int idxCmd) { // get the contact information MENUITEMINFOA mii = { 0 }; mii.cbSize = sizeof(mii); mii.fMask = MIIM_ID | MIIM_DATA; - if ( !GetMenuItemInfoA(Self->hRootMenu, Self->idCmdFirst + idxCmd, false, &mii)) + if (!GetMenuItemInfoA(Self->hRootMenu, Self->idCmdFirst + idxCmd, false, &mii)) return E_INVALIDARG; // get the pointer - TMenuDrawInfo *psd = (TMenuDrawInfo*)mii.dwItemData; + TMenuDrawInfo* psd = (TMenuDrawInfo*)mii.dwItemData; // the ID stored in the item pointer and the ID for the menu must match if (psd == nullptr || psd->wID != mii.wID) return E_INVALIDARG; @@ -761,7 +761,7 @@ HRESULT RequestTransfer(TShellExt *Self, int idxCmd) HANDLE hMap = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, IPC_PACKET_SIZE, IPC_PACKET_NAME); if (hMap != nullptr && GetLastError() != ERROR_ALREADY_EXISTS) { // map it to process - THeaderIPC *pipch = (THeaderIPC*)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); + THeaderIPC* pipch = (THeaderIPC*)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (pipch != nullptr) { // create the name of the object to be signalled by the ST lstrcpyA(pipch->SignalEventName, CreateUID(szBuf, sizeof(szBuf))); @@ -769,7 +769,7 @@ HRESULT RequestTransfer(TShellExt *Self, int idxCmd) HANDLE hReply = CreateEventA(nullptr, false, false, pipch->SignalEventName); if (hReply != nullptr) { if (psd->fTypes & dtCommand) { - if (psd->MenuCommandCallback) + if (psd->MenuCommandCallback) hr = psd->MenuCommandCallback(pipch, hTransfer, hReply); } else { @@ -801,14 +801,14 @@ HRESULT RequestTransfer(TShellExt *Self, int idxCmd) return hr; } -HRESULT TShellExt::InvokeCommand(CMINVOKECOMMANDINFO *pici) +HRESULT TShellExt::InvokeCommand(CMINVOKECOMMANDINFO * pici) { return RequestTransfer(this, LOWORD(UINT_PTR(pici->lpVerb))); } ///////////////////////////////////////////////////////////////////////////////////////// -HRESULT TShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult) +HRESULT TShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT * plResult) { LRESULT Dummy; if (plResult == nullptr) @@ -913,7 +913,7 @@ HRESULT TShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESU // store it msi->itemWidth = dx + ncm.iMenuWidth; msi->itemHeight = ncm.iMenuHeight + 2; - if (tS.cy > (int)msi->itemHeight) + if (tS.cy > (int)msi->itemHeight) msi->itemHeight += tS.cy - msi->itemHeight; // clean up SelectObject(hMemDC, hOldFont); diff --git a/plugins/ShellExt/src/shlfactory.cpp b/plugins/ShellExt/src/shlfactory.cpp index fba9fdabba..ab5480553c 100644 --- a/plugins/ShellExt/src/shlfactory.cpp +++ b/plugins/ShellExt/src/shlfactory.cpp @@ -9,19 +9,19 @@ TClassFactoryRec::TClassFactoryRec() : DllFactoryCount++; } -HRESULT TClassFactoryRec::QueryInterface(REFIID riid, void **ppvObject) +HRESULT TClassFactoryRec::QueryInterface(REFIID riid, void** ppvObject) { if (riid == IID_IUnknown) logA("TClassFactoryRec retrieved as IUnknown: %d\n", RefCount); else if (riid == IID_IClassFactory) logA("TClassFactoryRec retrieved as IClassFactory: %d\n", RefCount); else { - #ifdef LOG_ENABLED - RPC_CSTR szGuid; - UuidToStringA(&riid, &szGuid); - logA("TClassFactoryRec::QueryInterface {%s} failed\n", szGuid); - RpcStringFreeA(&szGuid); - #endif + #ifdef LOG_ENABLED + RPC_CSTR szGuid; + UuidToStringA(&riid, &szGuid); + logA("TClassFactoryRec::QueryInterface {%s} failed\n", szGuid); + RpcStringFreeA(&szGuid); + #endif *ppvObject = nullptr; return E_NOINTERFACE; } @@ -47,7 +47,7 @@ ULONG TClassFactoryRec::Release() return result; } -HRESULT TClassFactoryRec::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject) +HRESULT TClassFactoryRec::CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppvObject) { if (ppvObject == nullptr) return E_POINTER; @@ -61,7 +61,7 @@ HRESULT TClassFactoryRec::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void return E_OUTOFMEMORY; HRESULT hr = p->QueryInterface(riid, ppvObject); - if ( FAILED(hr)) + if (FAILED(hr)) delete p; return hr; } diff --git a/plugins/ShellExt/src/shlicons.cpp b/plugins/ShellExt/src/shlicons.cpp index 8f9162a7c0..1c6b2dbcb6 100644 --- a/plugins/ShellExt/src/shlicons.cpp +++ b/plugins/ShellExt/src/shlicons.cpp @@ -27,7 +27,7 @@ IWICImagingFactory* ARGB_GetWorker() return res; } -HBITMAP ARGB_BitmapFromIcon(IWICImagingFactory *Factory, HDC hDC, HICON hIcon) +HBITMAP ARGB_BitmapFromIcon(IWICImagingFactory* Factory, HDC hDC, HICON hIcon) { HBITMAP hBmp = nullptr; @@ -40,11 +40,11 @@ HBITMAP ARGB_BitmapFromIcon(IWICImagingFactory *Factory, HDC hDC, HICON hIcon) bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biBitCount = 32; - IWICBitmap *bitmap = nullptr; + IWICBitmap* bitmap = nullptr; HRESULT hr = Factory->CreateBitmapFromHICON(hIcon, &bitmap); if (hr == S_OK) { int cx, cy; - hr = bitmap->GetSize((PUINT)&cx, (PUINT)&cy); + hr = bitmap->GetSize((PUINT)& cx, (PUINT)& cy); if (hr == S_OK) { bmi.bmiHeader.biWidth = cx; bmi.bmiHeader.biHeight = -cy; diff --git a/plugins/ShellExt/src/shlipc.cpp b/plugins/ShellExt/src/shlipc.cpp index ac2ba3ef01..65e6541b4f 100644 --- a/plugins/ShellExt/src/shlipc.cpp +++ b/plugins/ShellExt/src/shlipc.cpp @@ -1,14 +1,14 @@ #include "stdafx.h" #include "shlcom.h" -TGroupNode* FindGroupNode(TGroupNode *p, const DWORD Hash, int Depth) +TGroupNode* FindGroupNode(TGroupNode* p, const DWORD Hash, int Depth) { while (p != nullptr) { if (p->Hash == Hash && p->Depth == Depth) return p; if (p->Left != nullptr) { - TGroupNode *q = FindGroupNode(p->Left, Hash, Depth); + TGroupNode* q = FindGroupNode(p->Left, Hash, Depth); if (q != nullptr) return q; } @@ -41,7 +41,7 @@ TGroupNode* AllocGroupNode(TGroupNodeList *list, TGroupNode *Root, int Depth) return p; } -void ipcPrepareRequests(int ipcPacketSize, THeaderIPC *pipch, DWORD fRequests) +void ipcPrepareRequests(int ipcPacketSize, THeaderIPC * pipch, DWORD fRequests) { // some fields may already have values like the event object name to open pipch->cbSize = sizeof(THeaderIPC); @@ -65,16 +65,16 @@ void ipcPrepareRequests(int ipcPacketSize, THeaderIPC *pipch, DWORD fRequests) pipch->DataPtrEnd = (TSlotIPC*)(LPSTR(pipch->DataPtr) + pipch->DataSize); pipch->DataFramePtr = pipch->DataPtr; // fill the data area - memset(pipch->DataPtr,0 , pipch->DataSize); + memset(pipch->DataPtr, 0, pipch->DataSize); } -DWORD ipcSendRequest(HANDLE hSignal, HANDLE hWaitFor, THeaderIPC *pipch, DWORD dwTimeoutMsecs) +DWORD ipcSendRequest(HANDLE hSignal, HANDLE hWaitFor, THeaderIPC * pipch, DWORD dwTimeoutMsecs) { // signal ST to work SetEvent(hSignal); // wait for reply, it should open a handle to hWaitFor... while (true) { - switch ( WaitForSingleObjectEx(hWaitFor, dwTimeoutMsecs, true)) { + switch (WaitForSingleObjectEx(hWaitFor, dwTimeoutMsecs, true)) { case WAIT_OBJECT_0: return pipch->fRequests; @@ -88,7 +88,7 @@ DWORD ipcSendRequest(HANDLE hSignal, HANDLE hWaitFor, THeaderIPC *pipch, DWORD d } } -TSlotIPC* ipcAlloc(THeaderIPC *pipch, int nSize) +TSlotIPC* ipcAlloc(THeaderIPC * pipch, int nSize) { // nSize maybe zero, in that case there is no string section --- UINT_PTR PSP = UINT_PTR(pipch->DataFramePtr) + sizeof(TSlotIPC) + nSize; diff --git a/plugins/ShellExt/src/stdafx.h b/plugins/ShellExt/src/stdafx.h index 27b3093433..aaa7a751a2 100644 --- a/plugins/ShellExt/src/stdafx.h +++ b/plugins/ShellExt/src/stdafx.h @@ -64,4 +64,4 @@ int OnOptionsInit(WPARAM wParam, LPARAM lParam); #define logA(A, ...) #endif -UINT murmur_hash(const char *str); +UINT murmur_hash(const char* str); diff --git a/plugins/ShellExt/src/utils.cpp b/plugins/ShellExt/src/utils.cpp index 131ee01dbb..372acb1a1e 100644 --- a/plugins/ShellExt/src/utils.cpp +++ b/plugins/ShellExt/src/utils.cpp @@ -2,7 +2,7 @@ /////////////////////////////////////////////////////////////////////////////// -UINT murmur_hash(const char *str) +UINT murmur_hash(const char* str) { size_t len = lstrlenA(str); @@ -15,7 +15,7 @@ UINT murmur_hash(const char *str) unsigned int h = (unsigned)len; // Mix 4 bytes at a time into the hash - const unsigned char *data = (const unsigned char*)str; + const unsigned char* data = (const unsigned char*)str; while (len >= 4) { unsigned int k = *(unsigned int*)data; @@ -32,11 +32,11 @@ UINT murmur_hash(const char *str) } // Handle the last few bytes of the input array - switch(len) { + switch (len) { case 3: h ^= data[2] << 16; case 2: h ^= data[1] << 8; case 1: h ^= data[0]; - h *= m; + h *= m; } // Do a few final mixes of the hash to ensure the last few diff --git a/plugins/ShellExt/src/version.h b/plugins/ShellExt/src/version.h index 6e70f9bf64..f90ed56d63 100644 --- a/plugins/ShellExt/src/version.h +++ b/plugins/ShellExt/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 2 #define __MINOR_VERSION 2 #define __RELEASE_NUM 0 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include -- cgit v1.2.3