From 08113fdd9815aa8a81eeebe56685eb9a36c74174 Mon Sep 17 00:00:00 2001 From: lx-s Date: Wed, 21 Dec 2022 11:54:06 +0100 Subject: [PATCH] Fixed further analyzer warnings --- WinMute/AboutDlg.cpp | 20 ++++++++++---------- WinMute/BluetoothDetector.cpp | 8 ++++---- WinMute/BluetoothDetector.h | 4 +++- WinMute/QuietHoursTimer.cpp | 18 +++++++++--------- WinMute/QuietHoursTimer.h | 4 ++-- WinMute/Settings_BluetoothDlg.cpp | 22 +++++++++++----------- WinMute/Settings_MuteDlg.cpp | 4 ++-- WinMute/Settings_WifiDlg.cpp | 10 +++++----- WinMute/TrayIcon.h | 2 +- WinMute/VersionHelper.h | 5 +++-- WinMute/VistaAudioSessionEvents.cpp | 14 +++++++------- WinMute/VistaAudioSessionEvents.h | 15 ++++++++------- WinMute/WMSettings.cpp | 2 +- WinMute/WMSettings.h | 2 +- WinMute/WiFiDetector.h | 6 ++++-- WinMute/WifiDetector.cpp | 10 +++++----- WinMute/WinMain.cpp | 4 ++-- WinMute/WinMute.cpp | 14 +++++++------- WinMute/WinMute.h | 14 +++++++------- 19 files changed, 92 insertions(+), 86 deletions(-) diff --git a/WinMute/AboutDlg.cpp b/WinMute/AboutDlg.cpp index 89f6887..9c953e1 100644 --- a/WinMute/AboutDlg.cpp +++ b/WinMute/AboutDlg.cpp @@ -96,21 +96,21 @@ struct AboutDlgData { } }; -static void InsertTabItem(HWND hTabCtrl, UINT id, const wchar_t *itemName) +static void InsertTabItem(HWND hTabCtrl, UINT id, const std::wstring& itemName) { constexpr int bufSize = 50; - wchar_t buf[bufSize]; + wchar_t buf[bufSize] = { L'\0' }; TC_ITEM tcItem; ZeroMemory(&tcItem, sizeof(tcItem)); tcItem.mask |= TCIF_TEXT; - StringCchCopy(buf, bufSize, itemName); + StringCchCopyW(buf, bufSize, itemName.c_str()); tcItem.pszText = buf; tcItem.cchTextMax = bufSize; TabCtrl_InsertItem(hTabCtrl, id, &tcItem); } -static void SwitchTab(AboutDlgData* dlgData, HWND hNewTab) +static void SwitchTab(AboutDlgData* dlgData, HWND hNewTab) noexcept { if (dlgData->hActiveTab != nullptr) { ShowWindow(dlgData->hActiveTab, SW_HIDE); @@ -158,7 +158,7 @@ static void ResizeTabs(HWND hTabCtrl, std::span tabs) } } -static INT_PTR CALLBACK About_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM lParam) +static INT_PTR CALLBACK About_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM lParam) noexcept { switch (msg) { case WM_INITDIALOG: @@ -168,10 +168,10 @@ static INT_PTR CALLBACK About_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM Edit_SetText(GetDlgItem(hDlg, IDC_ABOUTTEXT), aboutText.c_str()); return TRUE; case WM_NOTIFY: { - PNMLINK pNmLink = reinterpret_cast(lParam); + const PNMLINK pNmLink = reinterpret_cast(lParam); if (pNmLink->hdr.code == NM_CLICK || pNmLink->hdr.code == NM_RETURN) { - UINT_PTR ctrlId = pNmLink->hdr.idFrom; - LITEM item = pNmLink->item; + const UINT_PTR ctrlId = pNmLink->hdr.idFrom; + const LITEM item = pNmLink->item; if ((ctrlId == IDC_LINK_HOMEPAGE || ctrlId == IDC_LINK_TICKETS || ctrlId == IDC_LINK_PROJECT) @@ -187,7 +187,7 @@ static INT_PTR CALLBACK About_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM return FALSE; } -static INT_PTR CALLBACK About_LicenseDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM) +static INT_PTR CALLBACK About_LicenseDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM) noexcept { switch (msg) { case WM_INITDIALOG: @@ -208,7 +208,7 @@ static bool GetWinMuteVersion(std::wstring& versNumber) DWORD dummy; wchar_t szFileName[MAX_PATH]; GetModuleFileName(nullptr, szFileName, sizeof(szFileName)/sizeof(szFileName[0])); - DWORD versSize = GetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL, szFileName, &dummy); + const DWORD versSize = GetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL, szFileName, &dummy); LPVOID versData = malloc(versSize); if (versData != nullptr) { if (GetFileVersionInfoExW( diff --git a/WinMute/BluetoothDetector.cpp b/WinMute/BluetoothDetector.cpp index fd0f418..ba45a12 100644 --- a/WinMute/BluetoothDetector.cpp +++ b/WinMute/BluetoothDetector.cpp @@ -47,7 +47,7 @@ BluetoothDetector::~BluetoothDetector() } } -void BluetoothDetector::UnloadRadioNotifications() +void BluetoothDetector::UnloadRadioNotifications() noexcept { for (auto hDevNotify : notificationHandles_) { UnregisterDeviceNotification(hDevNotify); @@ -61,8 +61,8 @@ bool BluetoothDetector::LoadRadioNotifications() auto& log = WMLog::GetInstance(); notificationHandles_.clear(); - HANDLE btHandle; - BLUETOOTH_FIND_RADIO_PARAMS bfrp = { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; + HANDLE btHandle = nullptr; + const BLUETOOTH_FIND_RADIO_PARAMS bfrp = { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; HBLUETOOTH_RADIO_FIND hRadiosFind = BluetoothFindFirstRadio(&bfrp, &btHandle); if (hRadiosFind == nullptr) { log.WriteWindowsError(L"BluetoothFindFirstRadio", GetLastError()); @@ -88,7 +88,7 @@ bool BluetoothDetector::LoadRadioNotifications() notificationHandles_.push_back(devNotify); } } while (BluetoothFindNextRadio(hRadiosFind, &btHandle)); - DWORD dwLastError = GetLastError(); + const DWORD dwLastError = GetLastError(); if (dwLastError != ERROR_NO_MORE_ITEMS) { log.WriteWindowsError(L"BluetoothFindNextRadio", GetLastError()); UnloadRadioNotifications(); diff --git a/WinMute/BluetoothDetector.h b/WinMute/BluetoothDetector.h index 62baf90..a8ffe90 100644 --- a/WinMute/BluetoothDetector.h +++ b/WinMute/BluetoothDetector.h @@ -44,7 +44,9 @@ public: BluetoothDetector(); ~BluetoothDetector(); BluetoothDetector(const WifiDetector&) = delete; + BluetoothDetector(WifiDetector&&) = delete; BluetoothDetector& operator=(const WifiDetector&) = delete; + BluetoothDetector& operator=(WifiDetector&&) = delete; void SetDeviceList(const std::vector& devices, bool useDeviceList); @@ -61,7 +63,7 @@ private: std::vector notificationHandles_; bool LoadRadioNotifications(); - void UnloadRadioNotifications(); + void UnloadRadioNotifications() noexcept; bool initialized_; bool useDeviceList_; diff --git a/WinMute/QuietHoursTimer.cpp b/WinMute/QuietHoursTimer.cpp index 1bca8b9..7af79b2 100644 --- a/WinMute/QuietHoursTimer.cpp +++ b/WinMute/QuietHoursTimer.cpp @@ -35,17 +35,17 @@ POSSIBILITY OF SUCH DAMAGE. extern HINSTANCE hglobInstance; -static const int QUIETHOURS_TIMER_START_ID = 271020; -static const int QUIETHOURS_TIMER_END_ID = 271021; +static constexpr int QUIETHOURS_TIMER_START_ID = 271020; +static constexpr int QUIETHOURS_TIMER_END_ID = 271021; -static __int64 ConvertSystemTimeTo100NS(const LPSYSTEMTIME sysTime) +static std::int64_t ConvertSystemTimeTo100NS(const LPSYSTEMTIME sysTime) noexcept { FILETIME ft; SystemTimeToFileTime(sysTime, &ft); ULARGE_INTEGER ulInt; ulInt.HighPart = ft.dwHighDateTime; ulInt.LowPart = ft.dwLowDateTime; - return static_cast<__int64>(ulInt.QuadPart); + return static_cast(ulInt.QuadPart); } static bool IsQuietHours( @@ -53,9 +53,9 @@ static bool IsQuietHours( const LPSYSTEMTIME qhStart, const LPSYSTEMTIME qhEnd) { - __int64 iStart = ConvertSystemTimeTo100NS(qhStart); - __int64 iEnd = ConvertSystemTimeTo100NS(qhEnd); - __int64 iNow = ConvertSystemTimeTo100NS(now); + const std::int64_t iStart = ConvertSystemTimeTo100NS(qhStart); + std::int64_t iEnd = ConvertSystemTimeTo100NS(qhEnd); + const std::int64_t iNow = ConvertSystemTimeTo100NS(now); if (iEnd < iStart) { // Add one day @@ -89,7 +89,7 @@ static int GetDiffMillseconds(const LPSYSTEMTIME t1, const LPSYSTEMTIME t2) return static_cast(res); } -static VOID CALLBACK QuietHoursTimerProc(HWND hWnd, UINT msg, UINT_PTR id, DWORD msSinceSysStart) +static VOID CALLBACK QuietHoursTimerProc(HWND hWnd, UINT msg, UINT_PTR id, DWORD msSinceSysStart) noexcept { UNREFERENCED_PARAMETER(msg); UNREFERENCED_PARAMETER(msSinceSysStart); @@ -181,7 +181,7 @@ bool QuietHoursTimer::SetStart() start.wMinute = static_cast(((qhStart_ - start.wSecond) / 60) % 60); start.wHour = static_cast((qhStart_ - start.wMinute - start.wSecond) / 3600); - int timerQhStart = GetDiffMillseconds(&start, &now); + const int timerQhStart = GetDiffMillseconds(&start, &now); if (SetCoalescableTimer( hParent_, QUIETHOURS_TIMER_START_ID, diff --git a/WinMute/QuietHoursTimer.h b/WinMute/QuietHoursTimer.h index c362e75..3eea76e 100644 --- a/WinMute/QuietHoursTimer.h +++ b/WinMute/QuietHoursTimer.h @@ -35,8 +35,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "common.h" -static const int WM_WINMUTE_QUIETHOURS_START = WM_APP + 202; -static const int WM_WINMUTE_QUIETHOURS_END = WM_APP + 203; +static constexpr int WM_WINMUTE_QUIETHOURS_START = WM_APP + 202; +static constexpr int WM_WINMUTE_QUIETHOURS_END = WM_APP + 203; class QuietHoursTimer { public: diff --git a/WinMute/Settings_BluetoothDlg.cpp b/WinMute/Settings_BluetoothDlg.cpp index 550e957..ee9de6b 100644 --- a/WinMute/Settings_BluetoothDlg.cpp +++ b/WinMute/Settings_BluetoothDlg.cpp @@ -108,7 +108,7 @@ static INT_PTR CALLBACK Settings_BluetoothAddDlgProc(HWND hDlg, UINT msg, WPARAM case WM_COMMAND: if (LOWORD(wParam) == IDOK) { HWND hDevName = GetDlgItem(hDlg, IDC_BT_DEVICE_NAME); - int textLen = Edit_GetTextLength(hDevName); + const int textLen = Edit_GetTextLength(hDevName); if (textLen == 0) { EDITBALLOONTIP ebt; ZeroMemory(&ebt, sizeof(ebt)); @@ -118,7 +118,7 @@ static INT_PTR CALLBACK Settings_BluetoothAddDlgProc(HWND hDlg, UINT msg, WPARAM ebt.ttiIcon = TTI_INFO; Edit_ShowBalloonTip(hDevName, &ebt); } else { - wchar_t devNameBuf[BT_DEV_NAME_MAX_LEN + 1]; + wchar_t devNameBuf[BT_DEV_NAME_MAX_LEN + 1] = { 'L\0' }; BtDeviceName* btDevName = reinterpret_cast(GetWindowLongPtr(hDlg, GWLP_USERDATA)); if (btDevName != nullptr) { Edit_GetText(hDevName, devNameBuf, ARRAY_SIZE(devNameBuf)); @@ -157,7 +157,7 @@ static std::vector ExportBluetoothDeviceList(HWND hList) return items; } -static bool IsBluetoothAvailable() +static bool IsBluetoothAvailable() noexcept { HANDLE btHandle; BLUETOOTH_FIND_RADIO_PARAMS bfrp = { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; @@ -169,7 +169,7 @@ static bool IsBluetoothAvailable() return true; } -static BOOL CALLBACK ShowChildWindow(HWND hWnd, LPARAM lParam) +static BOOL CALLBACK ShowChildWindow(HWND hWnd, LPARAM lParam) noexcept { ShowWindow(hWnd, static_cast(lParam)); return TRUE; @@ -223,7 +223,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L HWND hBtNotAvail = GetDlgItem(hDlg, IDC_STATIC_BLUETOOTH_NOT_AVAILABLE); RECT r; GetClientRect(hBtNotAvail, &r); - const int margin = 20; + constexpr int margin = 20; SetWindowPos( hBtNotAvail, HWND_TOP, margin, margin, r.right, r.bottom, @@ -236,17 +236,17 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L case WM_COMMAND: { if (LOWORD(wParam) == IDC_ENABLE_BLUETOOTH_MUTE) { - DWORD checked = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE)); + const DWORD checked = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE)); Button_Enable(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE_DEVICE_LIST), checked == BST_CHECKED); } else if (LOWORD(wParam) == IDC_BLUETOOTH_LIST) { HWND hList = GetDlgItem(hDlg, IDC_BLUETOOTH_LIST); if (HIWORD(wParam) == LBN_SELCHANGE || HIWORD(wParam) == LBN_SELCANCEL) { - bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR); + const bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR); Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_EDIT), entrySelected); Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_REMOVE), entrySelected); } else if (HIWORD(wParam) == LBN_KILLFOCUS) { - bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR); + const bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR); Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_EDIT), entrySelected); Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_REMOVE), entrySelected); } @@ -271,9 +271,9 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L } } else if (LOWORD(wParam) == IDC_BLUETOOTH_EDIT) { HWND hList = GetDlgItem(hDlg, IDC_BLUETOOTH_LIST); - WPARAM sel = ListBox_GetCurSel(hList); + const WPARAM sel = ListBox_GetCurSel(hList); if (sel != LB_ERR) { - int len = ListBox_GetTextLen(hList, sel); + const int len = ListBox_GetTextLen(hList, sel); wchar_t* textBuf = nullptr; if (len != LB_ERR) { if ((textBuf = new wchar_t[static_cast(len) + 1]) != nullptr) { @@ -303,7 +303,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L } } else if (LOWORD(wParam) == IDC_BLUETOOTH_REMOVE) { HWND hList = GetDlgItem(hDlg, IDC_BLUETOOTH_LIST); - WPARAM sel = ListBox_GetCurSel(hList); + const WPARAM sel = ListBox_GetCurSel(hList); if (sel != LB_ERR) { ListBox_DeleteString(hList, sel); if (ListBox_GetCount(hList) == 0) { diff --git a/WinMute/Settings_MuteDlg.cpp b/WinMute/Settings_MuteDlg.cpp index c027dc8..c9a456f 100644 --- a/WinMute/Settings_MuteDlg.cpp +++ b/WinMute/Settings_MuteDlg.cpp @@ -35,13 +35,13 @@ POSSIBILITY OF SUCH DAMAGE. static void SetCheckButton(HWND hBtn, const WMSettings& settings, SettingsKey key) { - DWORD enabled = !!settings.QueryValue(key); + const DWORD enabled = !!settings.QueryValue(key); Button_SetCheck(hBtn, enabled ? BST_CHECKED : BST_UNCHECKED); } static void SetOption(HWND hBtn, WMSettings& settings, SettingsKey key) { - int enable = Button_GetCheck(hBtn) == BST_CHECKED; + const int enable = Button_GetCheck(hBtn) == BST_CHECKED; settings.SetValue(key, enable); } diff --git a/WinMute/Settings_WifiDlg.cpp b/WinMute/Settings_WifiDlg.cpp index b8991f6..cf17a4c 100644 --- a/WinMute/Settings_WifiDlg.cpp +++ b/WinMute/Settings_WifiDlg.cpp @@ -194,16 +194,16 @@ INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM case WM_COMMAND: { if (LOWORD(wParam) == IDC_ENABLE_WIFI_MUTE) { - DWORD checked = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_WIFI_MUTE)); + const DWORD checked = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_WIFI_MUTE)); Button_Enable(GetDlgItem(hDlg, IDC_IS_PERMITLIST), checked == BST_CHECKED); } else if (LOWORD(wParam) == IDC_WIFI_LIST) { HWND hList = GetDlgItem(hDlg, IDC_WIFI_LIST); if (HIWORD(wParam) == LBN_SELCHANGE || HIWORD(wParam) == LBN_SELCANCEL) { - bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR); + const bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR); Button_Enable(GetDlgItem(hDlg, IDC_WIFI_EDIT), entrySelected); Button_Enable(GetDlgItem(hDlg, IDC_WIFI_REMOVE), entrySelected); } else if (HIWORD(wParam) == LBN_KILLFOCUS) { - bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR); + const bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR); Button_Enable(GetDlgItem(hDlg, IDC_WIFI_EDIT), entrySelected); Button_Enable(GetDlgItem(hDlg, IDC_WIFI_REMOVE), entrySelected); } @@ -228,9 +228,9 @@ INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM } } else if (LOWORD(wParam) == IDC_WIFI_EDIT) { HWND hList = GetDlgItem(hDlg, IDC_WIFI_LIST); - WPARAM sel = ListBox_GetCurSel(hList); + const WPARAM sel = ListBox_GetCurSel(hList); if (sel != LB_ERR) { - int len = ListBox_GetTextLen(hList, sel); + const int len = ListBox_GetTextLen(hList, sel); wchar_t *textBuf = nullptr; if (len != LB_ERR) { if ((textBuf = new wchar_t[static_cast(len) + 1]) != nullptr) { diff --git a/WinMute/TrayIcon.h b/WinMute/TrayIcon.h index 610401a..3176e0a 100644 --- a/WinMute/TrayIcon.h +++ b/WinMute/TrayIcon.h @@ -52,7 +52,7 @@ public: bool show); void Hide(); void Show(); - bool IsShown() const { return iconVisible_; } + bool IsShown() const noexcept { return iconVisible_; } void ChangeIcon(HICON hNewIcon); void ChangeText(const std::wstring& tooltip); void ShowPopup(const std::wstring& title, const std::wstring& text) const; diff --git a/WinMute/VersionHelper.h b/WinMute/VersionHelper.h index dd810e3..58cd99b 100644 --- a/WinMute/VersionHelper.h +++ b/WinMute/VersionHelper.h @@ -37,9 +37,10 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef _versionhelpers_H_INCLUDED_ // avoid conflict with MS versionhelpers -inline bool IsWindowsVersionOrGreater(WORD wMajorVersion, +inline bool IsWindowsVersionOrGreater( + WORD wMajorVersion, WORD wMinorVersion, - WORD wServicePackMajor) + WORD wServicePackMajor) noexcept { OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, { 0 }, 0, 0 }; DWORDLONG const dwlConditionMask = VerSetConditionMask( diff --git a/WinMute/VistaAudioSessionEvents.cpp b/WinMute/VistaAudioSessionEvents.cpp index 920a5e9..1d5d22a 100644 --- a/WinMute/VistaAudioSessionEvents.cpp +++ b/WinMute/VistaAudioSessionEvents.cpp @@ -76,38 +76,38 @@ HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::QueryInterface( } HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnDisplayNameChanged( - LPCWSTR /*newDisplayName*/, LPCGUID /*eventContext*/) + LPCWSTR /*newDisplayName*/, LPCGUID /*eventContext*/) noexcept { return S_OK; } HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnIconPathChanged( - LPCWSTR /*newIconPath*/, LPCGUID /*eventContext*/) + LPCWSTR /*newIconPath*/, LPCGUID /*eventContext*/) noexcept { return S_OK; } HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnSimpleVolumeChanged( - float /*newVolume*/, BOOL /*newMute*/, LPCGUID /*eventContext*/) + float /*newVolume*/, BOOL /*newMute*/, LPCGUID /*eventContext*/) noexcept { return S_OK; } HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnChannelVolumeChanged( DWORD /*channelCount*/, float* /*newChannelVolumeArray[]*/, - DWORD /*changedChannel*/, LPCGUID /*eventContext*/) + DWORD /*changedChannel*/, LPCGUID /*eventContext*/) noexcept { return S_OK; } HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnGroupingParamChanged( - LPCGUID /*newGroupingParam*/, LPCGUID /*eventContext*/) + LPCGUID /*newGroupingParam*/, LPCGUID /*eventContext*/) noexcept { return S_OK; } HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnStateChanged( - AudioSessionState /*newState*/) + AudioSessionState /*newState*/) noexcept { return S_OK; } @@ -116,7 +116,7 @@ HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnStateChanged( * http://blogs.msdn.com/b/larryosterman/archive/2007/10/31/what-happens-when-audio-rendering-fails.aspx * for detailed information about each of these entries */ HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnSessionDisconnected( - AudioSessionDisconnectReason disconnectReason) + AudioSessionDisconnectReason disconnectReason) noexcept { switch (disconnectReason) { diff --git a/WinMute/VistaAudioSessionEvents.h b/WinMute/VistaAudioSessionEvents.h index 752188c..103d506 100644 --- a/WinMute/VistaAudioSessionEvents.h +++ b/WinMute/VistaAudioSessionEvents.h @@ -52,31 +52,32 @@ public: // Notification methods for audio session events HRESULT STDMETHODCALLTYPE OnDisplayNameChanged( LPCWSTR newDisplayName, - LPCGUID eventContext); + LPCGUID eventContext) noexcept override; HRESULT STDMETHODCALLTYPE OnIconPathChanged( LPCWSTR newIconPath, - LPCGUID eventContext); + LPCGUID eventContext) noexcept override; HRESULT STDMETHODCALLTYPE OnSimpleVolumeChanged( float newVolume, BOOL newMute, - LPCGUID eventContext); + LPCGUID eventContext) noexcept override; HRESULT STDMETHODCALLTYPE OnChannelVolumeChanged( DWORD channelCount, float newChannelVolumeArray[], DWORD changedChannel, - LPCGUID eventContext); + LPCGUID eventContext) noexcept override; HRESULT STDMETHODCALLTYPE OnGroupingParamChanged( LPCGUID newGroupingParam, - LPCGUID eventContext); + LPCGUID eventContext) noexcept override; - HRESULT STDMETHODCALLTYPE OnStateChanged(AudioSessionState newState); + HRESULT STDMETHODCALLTYPE OnStateChanged( + AudioSessionState newState) noexcept override; HRESULT STDMETHODCALLTYPE OnSessionDisconnected( - AudioSessionDisconnectReason disconnectReason); + AudioSessionDisconnectReason disconnectReason) noexcept override; private: LONG ref_; diff --git a/WinMute/WMSettings.cpp b/WinMute/WMSettings.cpp index 0491476..6cf51bc 100644 --- a/WinMute/WMSettings.cpp +++ b/WinMute/WMSettings.cpp @@ -254,7 +254,7 @@ bool WMSettings::Init() return true; } -void WMSettings::Unload() +void WMSettings::Unload() noexcept { RegCloseKey(hSettingsKey_); hSettingsKey_ = nullptr; diff --git a/WinMute/WMSettings.h b/WinMute/WMSettings.h index 9bf652d..8e2d905 100644 --- a/WinMute/WMSettings.h +++ b/WinMute/WMSettings.h @@ -65,7 +65,7 @@ public: WMSettings& operator=(const WMSettings&) = delete; bool Init(); - void Unload(); + void Unload() noexcept; bool IsAutostartEnabled(); void EnableAutostart(bool enable); diff --git a/WinMute/WiFiDetector.h b/WinMute/WiFiDetector.h index 3ae67cf..7667b46 100644 --- a/WinMute/WiFiDetector.h +++ b/WinMute/WiFiDetector.h @@ -40,13 +40,15 @@ constexpr int WM_WIFISTATUSCHANGED = WM_USER + 400; class WifiDetector { public: - WifiDetector(); + WifiDetector() noexcept; ~WifiDetector(); WifiDetector(const WifiDetector&) = delete; + WifiDetector(WifiDetector&&) = delete; WifiDetector& operator=(const WifiDetector&) = delete; + WifiDetector &operator=(WifiDetector&&) = delete; bool Init(HWND hNotifyWnd); - void Unload(); + void Unload() noexcept; void SetNetworkList(const std::vector& networks, bool isMuteList); void CheckNetwork(); diff --git a/WinMute/WifiDetector.cpp b/WinMute/WifiDetector.cpp index 227a5a0..b70b7fa 100644 --- a/WinMute/WifiDetector.cpp +++ b/WinMute/WifiDetector.cpp @@ -44,7 +44,7 @@ static void WlanNotificationCallback( } -WifiDetector::WifiDetector() +WifiDetector::WifiDetector() noexcept : hNotifyWnd_(nullptr), wlanHandle_(nullptr), isMuteList_(true), initialized_(false) { } @@ -53,7 +53,7 @@ WifiDetector::~WifiDetector() { } -void WifiDetector::Unload() +void WifiDetector::Unload() noexcept { if (initialized_) { WlanRegisterNotification(wlanHandle_, WLAN_NOTIFICATION_SOURCE_NONE, @@ -103,7 +103,7 @@ void WifiDetector::CheckNetwork() PrintWindowsError(L"WlanEnumInterfaces", wlanErr); } else { for (; ifList->dwIndex < ifList->dwNumberOfItems; ++ifList->dwIndex) { - PWLAN_AVAILABLE_NETWORK_LIST availList; + PWLAN_AVAILABLE_NETWORK_LIST availList = nullptr; wlanErr = WlanGetAvailableNetworkList( wlanHandle_, &ifList->InterfaceInfo[ifList->dwIndex].InterfaceGuid, @@ -114,14 +114,14 @@ void WifiDetector::CheckNetwork() PrintWindowsError(L"WlanGetAvailableNetworkList", wlanErr); } else { for (; availList->dwIndex < availList->dwNumberOfItems; ++availList->dwIndex) { - PWLAN_AVAILABLE_NETWORK net = &availList->Network[availList->dwIndex]; + const PWLAN_AVAILABLE_NETWORK net = &availList->Network[availList->dwIndex]; if (net->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { const auto it = std::find(std::begin(networks_), std::end(networks_), net->strProfileName); if (isMuteList_ && it != std::end(networks_) || !isMuteList_ && it == std::end(networks_)) { - size_t profileNameLen = lstrlen(net->strProfileName); + const size_t profileNameLen = lstrlen(net->strProfileName); wchar_t* wiFiName = new wchar_t[profileNameLen + 1]; StringCchCopy(wiFiName, profileNameLen + 1, net->strProfileName); SendMessage(hNotifyWnd_, WM_WIFISTATUSCHANGED, 1, diff --git a/WinMute/WinMain.cpp b/WinMute/WinMain.cpp index aa2eeb1..8e4c2cd 100644 --- a/WinMute/WinMain.cpp +++ b/WinMute/WinMain.cpp @@ -97,7 +97,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, // // - if (CoInitializeEx(0, COINIT_APARTMENTTHREADED) != S_OK) { + if (CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED) != S_OK) { TaskDialog(nullptr, nullptr, PROGRAM_NAME, @@ -110,7 +110,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, return FALSE; } - MSG msg = { 0 }; + MSG msg = { nullptr }; WinMute program; if (program.Init()) { while (GetMessage(&msg, nullptr, 0, 0)) { diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index 56703c9..894b329 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -101,7 +101,7 @@ static int IsDarkMode(bool& isDarkMode) return rc; } -static bool IsCurrentSessionRemoteable() +static bool IsCurrentSessionRemoteable() noexcept { bool isRemoteable = false; @@ -113,7 +113,7 @@ static bool IsCurrentSessionRemoteable() lResult = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TERMINAL_SERVER_KEY, 0, KEY_READ, &hRegKey); if (lResult == ERROR_SUCCESS) { - DWORD dwGlassSessionId; + DWORD dwGlassSessionId = 0; DWORD cbGlassSessionId = sizeof(dwGlassSessionId); DWORD dwType; @@ -147,7 +147,7 @@ WinMute::WinMute() : { } -WinMute::~WinMute() +WinMute::~WinMute() noexcept { Unload(); } @@ -337,7 +337,7 @@ bool WinMute::LoadSettings() settings_.SetValue(SettingsKey::MUTE_ON_BLUETOOTH, FALSE); } else { muteCtrl_.SetMuteOnBluetoothDisconnect(true); - bool muteOnWithDeviceList = settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST); + const bool muteOnWithDeviceList = settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST); btDetector_.SetDeviceList(settings_.GetBluetoothDevicesA(), muteOnWithDeviceList); } } @@ -353,7 +353,7 @@ bool WinMute::LoadSettings() L"WLAN muting will be disabled on this computer"); settings_.SetValue(SettingsKey::MUTE_ON_WLAN, FALSE); } else { - bool isMuteList = !settings_.QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST); + const bool isMuteList = !settings_.QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST); wifiDetector_.SetNetworkList(settings_.GetWifiNetworks(), isMuteList); wifiDetector_.CheckNetwork(); } @@ -362,7 +362,7 @@ bool WinMute::LoadSettings() return true; } -void WinMute::ToggleMenuCheck(UINT item, bool* setting) +void WinMute::ToggleMenuCheck(UINT item, bool* setting) noexcept { UINT state = GetMenuState(hTrayMenu_, item, MF_BYCOMMAND); if (state & MF_CHECKED) { @@ -614,7 +614,7 @@ LRESULT CALLBACK WinMute::WindowProc( return DefWindowProc(hWnd, msg, wParam, lParam); } -void WinMute::Unload() +void WinMute::Unload() noexcept { settings_.Unload(); } diff --git a/WinMute/WinMute.h b/WinMute/WinMute.h index 41484da..c794c81 100644 --- a/WinMute/WinMute.h +++ b/WinMute/WinMute.h @@ -40,7 +40,11 @@ class WinAudio; class WinMute { public: WinMute(); - ~WinMute(); + WinMute(const WinMute&) = delete; + WinMute(WinMute&&) = delete; + WinMute& operator=(const WinMute &) = delete; + WinMute& operator=(WinMute&&) = delete; + ~WinMute() noexcept; bool Init(); void Close(); @@ -73,11 +77,7 @@ private: bool InitTrayMenu(); bool LoadSettings(); - void Unload(); - - void ToggleMenuCheck(UINT item, bool* setting); + void Unload() noexcept; - // Disable copying - WinMute(const WinMute&) = delete; - WinMute& operator=(const WinMute&) = delete; + void ToggleMenuCheck(UINT item, bool* setting) noexcept; }; -- 2.43.0