]> repos.lx-s.de Git - winmute.git/commitdiff
Fixed further analyzer warnings
authorlx-s <lx-s@users.noreply.github.com>
Wed, 21 Dec 2022 10:54:06 +0000 (11:54 +0100)
committerlx-s <lx-s@users.noreply.github.com>
Wed, 21 Dec 2022 10:54:06 +0000 (11:54 +0100)
19 files changed:
WinMute/AboutDlg.cpp
WinMute/BluetoothDetector.cpp
WinMute/BluetoothDetector.h
WinMute/QuietHoursTimer.cpp
WinMute/QuietHoursTimer.h
WinMute/Settings_BluetoothDlg.cpp
WinMute/Settings_MuteDlg.cpp
WinMute/Settings_WifiDlg.cpp
WinMute/TrayIcon.h
WinMute/VersionHelper.h
WinMute/VistaAudioSessionEvents.cpp
WinMute/VistaAudioSessionEvents.h
WinMute/WMSettings.cpp
WinMute/WMSettings.h
WinMute/WiFiDetector.h
WinMute/WifiDetector.cpp
WinMute/WinMain.cpp
WinMute/WinMute.cpp
WinMute/WinMute.h

index 89f6887f0c2886efc6f1b48ce79c22ca510d8e7e..9c953e1f15b0fad6981959857ab8fddda916b357 100644 (file)
@@ -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<HWND> 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<PNMLINK>(lParam);
+      const PNMLINK pNmLink = reinterpret_cast<PNMLINK>(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(
index fd0f418025b0b67c75388eae2760b55f51555954..ba45a127ade116b810b3774a603a9cfe7bd32591 100644 (file)
@@ -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();
index 62baf9059b2da92515c2c1aa5b0552c543a36a49..a8ffe903a1c0488c6eb11c4bb6fe82102e63660c 100644 (file)
@@ -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<std::string>& devices, bool useDeviceList);
 
@@ -61,7 +63,7 @@ private:
    std::vector<HDEVNOTIFY> notificationHandles_;
 
    bool LoadRadioNotifications();
-   void UnloadRadioNotifications();
+   void UnloadRadioNotifications() noexcept;
 
    bool initialized_;
    bool useDeviceList_;
index 1bca8b9d71b311a781bbab8eb4f384a369527e55..7af79b2b8c4d7bc8b30e525f92da058ae12e644a 100644 (file)
@@ -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<std::int64_t>(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<int>(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<WORD>(((qhStart_ - start.wSecond) / 60) % 60);
    start.wHour = static_cast<WORD>((qhStart_ - start.wMinute - start.wSecond) / 3600);
 
-   int timerQhStart = GetDiffMillseconds(&start, &now);
+   const int timerQhStart = GetDiffMillseconds(&start, &now);
    if (SetCoalescableTimer(
          hParent_,
          QUIETHOURS_TIMER_START_ID,
index c362e75f495abd3d13f4246657b64f7fd2631bb4..3eea76e5aca5ad28487ed5dd03d7921e0f062c5a 100644 (file)
@@ -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:
index 550e957b3899b46f361526e5d0de18ec82486125..ee9de6b93b07a063d546da70bb0d916c1b21b399 100644 (file)
@@ -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<BtDeviceName*>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
             if (btDevName != nullptr) {
                Edit_GetText(hDevName, devNameBuf, ARRAY_SIZE(devNameBuf));
@@ -157,7 +157,7 @@ static std::vector<std::wstring> 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<int>(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<size_t>(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) {
index c027dc89408bb75a0a06a34143cc0aa4157c2ce6..c9a456fe8304a3fc3679a4ed6390ddfa620ce6e8 100644 (file)
@@ -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);
 }
 
index b8991f6855a60016ccdf73003581e1ba415e319c..cf17a4c93bdab980068278a00ef5a1a2eadbc57b 100644 (file)
@@ -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<size_t>(len) + 1]) != nullptr) {
index 610401afede28b12cf14664a0629f9be288580e2..3176e0a880c5408d88f4e1f53a128da4e5dc0ddc 100644 (file)
@@ -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;
index dd810e3013dcff900a15fefaec850be6e5c77c35..58cd99b5e56823c466124734a88e5336434d175c 100644 (file)
@@ -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(
index 920a5e9bf0f771e3165dc6c29234aace90b5509f..1d5d22aebd5dc05610bf65348fdac3143abe3b95 100644 (file)
@@ -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) {
index 752188c2ecba557d3f8eb470b396e340aade1455..103d506d598741a00c6f9639578bec2b25467b58 100644 (file)
@@ -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_;
index 04914766c60ef1f18d8d5b833c0397756c148054..6cf51bc5f49e885f7d065c33c2a90baf17c17b77 100644 (file)
@@ -254,7 +254,7 @@ bool WMSettings::Init()
    return true;
 }
 
-void WMSettings::Unload()
+void WMSettings::Unload() noexcept
 {
    RegCloseKey(hSettingsKey_);
    hSettingsKey_ = nullptr;
index 9bf652df4124303b836bd41aae3b24d48f2e5889..8e2d905f0276213a6053265b8200c9b01006300b 100644 (file)
@@ -65,7 +65,7 @@ public:
    WMSettings& operator=(const WMSettings&) = delete;
 
    bool Init();
-   void Unload();
+   void Unload() noexcept;
 
    bool IsAutostartEnabled();
    void EnableAutostart(bool enable);
index 3ae67cf6ca739c50b037a09e3311733624b94c7c..7667b46c599e52c26aa3df34ef472f96e9409772 100644 (file)
@@ -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<std::wstring>& networks, bool isMuteList);
 
    void CheckNetwork();
index 227a5a0a50b0abb7f3198522873c4e0ab510e412..b70b7fa99dfa7fefd33b64e98ac0ceb5a54e138e 100644 (file)
@@ -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,
index aa2eeb164a416460ace4f9105e8a8a76b1dd520d..8e4c2cd504ba3ba98578e29c5c8ae6bd17a288e8 100644 (file)
@@ -97,7 +97,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance,
    // </Init Common Controls>
 
    // <Init COM>
-   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)) {
index 56703c9da79d60a472c336d2352585b9df404047..894b329d329866c5f0a4bdcd925fc5442fabe2d3 100644 (file)
@@ -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();
 }
index 41484dabc40ec781901c3ac90b27dfa0c8f9ea53..c794c818052df3132a36b2da803d2a6fbb618c25 100644 (file)
@@ -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;
 };