From f52b5cc86d9eff2494902157c8fc0a4e019a3c95 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 15 Aug 2017 13:49:37 +0300 Subject: fixes #799 (Crash on receiving msg in FB group chat) --- src/core/stdmsg/src/msgdialog.cpp | 6 +++--- src/core/stdmsg/src/msgs.cpp | 19 ------------------- src/core/stdmsg/src/msgs.h | 2 +- src/mir_app/src/mir_app.def | 2 ++ src/mir_app/src/mir_app64.def | 2 ++ src/mir_app/src/srmm_util.cpp | 40 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 758842535e..7646c4e7ed 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -561,10 +561,10 @@ void CSrmmWindow::SetupStatusBar() SendMessage(m_hwnd, DM_STATUSICONCHANGE, 0, 0); } -void CSrmmWindow::SetStatusData(StatusTextData *st) +void CSrmmWindow::SetStatusText(const wchar_t *wszText, HICON hIcon) { - SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, (LPARAM)(st == nullptr ? 0 : st->hIcon)); - SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)(st == nullptr ? L"" : st->tszText)); + SendMessage(m_pOwner->m_hwndStatus, SB_SETICON, 0, (LPARAM)hIcon); + SendMessage(m_pOwner->m_hwndStatus, SB_SETTEXT, 0, (LPARAM)wszText); } void CSrmmWindow::UpdateReadChars() diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index bffa4588be..6d302f3111 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -479,24 +479,6 @@ static int PrebuildContactMenu(WPARAM hContact, LPARAM) return 0; } -static INT_PTR SetStatusText(WPARAM wParam, LPARAM lParam) -{ - StatusTextData *st = (StatusTextData*)lParam; - if (st == nullptr) - return 1; - - HWND hwnd = Srmm_FindWindow(wParam); - if (hwnd == nullptr) - return 1; - - CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if (dat == nullptr) - return 1; - - dat->SetStatusData(st); - return 0; -} - static wchar_t tszError[] = LPGENW("Miranda could not load the built-in message module, msftedit.dll is missing. Press 'Yes' to continue loading Miranda."); int LoadSendRecvMessageModule(void) @@ -521,7 +503,6 @@ int LoadSendRecvMessageModule(void) CreateServiceFunction(MS_MSG_SENDMESSAGE, SendMessageCommand); CreateServiceFunction(MS_MSG_SENDMESSAGEW, SendMessageCommand_W); - CreateServiceFunction(MS_MSG_SETSTATUSTEXT, SetStatusText); CreateServiceFunction("SRMsg/ReadMessage", ReadMessageCommand); SkinAddNewSoundEx("RecvMsgActive", LPGEN("Instant messages"), LPGEN("Incoming (focused window)")); diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index fea335010a..a94cb6a08d 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -112,6 +112,7 @@ public: virtual void CloseTab() override; virtual void LoadSettings() override {} virtual void ScrollToBottom() override; + virtual void SetStatusText(const wchar_t*, HICON) override; virtual void UpdateTitle() override {} void OnSplitterMoved(CSplitter*); @@ -120,7 +121,6 @@ public: void OnOptionsApplied(bool bUpdateAvatar); - void SetStatusData(StatusTextData*); void UpdateReadChars(void); __forceinline MCONTACT getActiveContact() const diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 890a9eec7f..a0addf8ff5 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -451,3 +451,5 @@ Hotkey_Subclass @455 Hotkey_Unregister @456 Hotkey_Unsubclass @457 Hotkey_Check @458 +?SetStatusText@CSrmmBaseDialog@@UAEXPB_WPAUHICON__@@@Z @459 NONAME +Srmm_SetStatusText @460 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index f5e2debc70..963f8cd9ad 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -451,3 +451,5 @@ Hotkey_Subclass @455 Hotkey_Unregister @456 Hotkey_Unsubclass @457 Hotkey_Check @458 +?SetStatusText@CSrmmBaseDialog@@UEAAXPEB_WPEAUHICON__@@@Z @459 NONAME +Srmm_SetStatusText @460 diff --git a/src/mir_app/src/srmm_util.cpp b/src/mir_app/src/srmm_util.cpp index ad0abe21a3..f9e7ed65c5 100644 --- a/src/mir_app/src/srmm_util.cpp +++ b/src/mir_app/src/srmm_util.cpp @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "chat.h" +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(DWORD) CALLBACK Srmm_LogStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) { LOGSTREAMDATA *lstrdat = (LOGSTREAMDATA*)dwCookie; @@ -50,6 +52,8 @@ MIR_APP_DLL(DWORD) CALLBACK Srmm_LogStreamCallback(DWORD_PTR dwCookie, LPBYTE pb return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(int) Srmm_GetWindowData(MCONTACT hContact, MessageWindowData &mwd) { if (hContact == 0) @@ -71,12 +75,48 @@ MIR_APP_DLL(int) Srmm_GetWindowData(MCONTACT hContact, MessageWindowData &mwd) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(void) Srmm_Broadcast(UINT msg, WPARAM wParam, LPARAM lParam) { WindowList_Broadcast(g_hWindowList, msg, wParam, lParam); } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(HWND) Srmm_FindWindow(MCONTACT hContact) { return WindowList_Find(g_hWindowList, hContact); } + +///////////////////////////////////////////////////////////////////////////////////////// +// serializes all thread-unsafe operation to the first thread + +struct SSTParam +{ + HWND hwnd; + const wchar_t *wszText; + HICON hIcon; +}; + +static INT_PTR CALLBACK sttSetStatusText(void *_p) +{ + SSTParam *param = (SSTParam*)_p; + + CSrmmBaseDialog *pDlg = (CSrmmBaseDialog*)GetWindowLongPtr(param->hwnd, GWLP_USERDATA); + if (pDlg != nullptr) + pDlg->SetStatusText((param->wszText == nullptr) ? L"" : param->wszText, param->hIcon); + return 0; +} + +MIR_APP_DLL(void) Srmm_SetStatusText(MCONTACT hContact, const wchar_t *wszText, HICON hIcon) +{ + HWND hwnd = Srmm_FindWindow(hContact); + if (hwnd == nullptr) + hwnd = Srmm_FindWindow(db_mc_getMeta(hContact)); + if (hwnd == nullptr) + return; + + SSTParam param = { hwnd, wszText, hIcon }; + CallFunctionSync(sttSetStatusText, ¶m); +} -- cgit v1.2.3