]> repos.lx-s.de Git - winmute.git/commitdiff
Removed TCHAR, _T(), etc.
authorAlexander Steinhöfer <kontakt@lx-s.de>
Wed, 3 Aug 2022 07:18:48 +0000 (09:18 +0200)
committerAlexander Steinhöfer <kontakt@lx-s.de>
Wed, 3 Aug 2022 07:18:48 +0000 (09:18 +0200)
28 files changed:
WinMute/AboutDlg.cpp
WinMute/BaseTypes.h [deleted file]
WinMute/MuteControl.cpp
WinMute/MuteControl.h
WinMute/QuietHoursTimer.cpp
WinMute/ScreensaverNotifier.cpp
WinMute/SettingsDlg.cpp
WinMute/Settings_BluetoothDlg.cpp
WinMute/Settings_GeneralDlg.cpp
WinMute/Settings_QuietHoursDlg.cpp
WinMute/Settings_WifiDlg.cpp
WinMute/TrayIcon.cpp
WinMute/TrayIcon.h
WinMute/Utility.cpp
WinMute/VistaAudio.cpp
WinMute/VistaAudioSessionEvents.cpp
WinMute/WMLog.cpp
WinMute/WMLog.h
WinMute/WMSettings.cpp
WinMute/WMSettings.h
WinMute/WiFiDetector.h
WinMute/WifiDetector.cpp
WinMute/WinAudio.h
WinMute/WinMain.cpp
WinMute/WinMute.cpp
WinMute/WinMute.vcxproj
WinMute/WinMute.vcxproj.filters
WinMute/common.h

index 21d32fec8d804b160442903f80cdd107d79e5f33..05291ace8a43fb951d236cb63beae688a9324c13 100644 (file)
@@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #include "common.h"
 
-static const TCHAR *licenseText = _T("\
+static const wchar_t *licenseText = L"\
 WinMute\r\n\
 Copyright(c) 2022, Alexander Steinhoefer\r\n\
 \r\n\
@@ -64,9 +64,9 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r\n\
 LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY\r\n\
 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r\n\
 POSSIBILITY OF SUCH DAMAGE.\r\n\
-");
+";
 
-static const TCHAR *aboutText = _T("\
+static const wchar_t *aboutText = L"\
 WinMute is developed by Alexander Steinhoefer\r\n\
 in his spare time.\r\n\
 \r\n\
@@ -76,7 +76,7 @@ Contributions in the form of code, tickets or\r\n\
 feature requests are very welcome.\r\n\
 \r\n\
 Thank your for using this little tool!\r\n\
-");
+";
 
 enum AboutTabsIDs {
    ABOUT_TAB_GENERAL = 0,
@@ -97,10 +97,10 @@ struct AboutDlgData {
    }
 };
 
-static void InsertTabItem(HWND hTabCtrl, UINT id, const TCHAR* itemName)
+static void InsertTabItem(HWND hTabCtrl, UINT id, const wchar_t *itemName)
 {
    constexpr int bufSize = 50;
-   TCHAR buf[bufSize];
+   wchar_t buf[bufSize];
    TC_ITEM tcItem;
    ZeroMemory(&tcItem, sizeof(tcItem));
    tcItem.mask |= TCIF_TEXT;
@@ -136,7 +136,7 @@ static void ResizeTabs(HWND hTabCtrl, HWND* hTabs, int tabCount)
 
    HDWP hdwp = BeginDeferWindowPos(tabCount);
    if (hdwp == NULL) {
-      PrintWindowsError(_T("BeginDeferWindowPos"), GetLastError());
+      PrintWindowsError(L"BeginDeferWindowPos", GetLastError());
    } else {
       for (int i = 0; i < tabCount; ++i) {
          HDWP newHdwp = DeferWindowPos(
@@ -149,7 +149,7 @@ static void ResizeTabs(HWND hTabCtrl, HWND* hTabs, int tabCount)
             tabCtrlRect.bottom - tabCtrlRect.top,
             0);
          if (hdwp == NULL) {
-            PrintWindowsError(_T("DeferWindowPos"), GetLastError());
+            PrintWindowsError(L"DeferWindowPos", GetLastError());
             break;
          } else {
             hdwp = newHdwp;
@@ -177,8 +177,7 @@ static INT_PTR CALLBACK About_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM
               || ctrlId == IDC_LINK_TICKETS
               || ctrlId == IDC_LINK_PROJECT)
             && item.iLink == 0) {
-            ShellExecute(nullptr, _T("open"), item.szUrl, nullptr, nullptr,
-               SW_SHOW);
+            ShellExecuteW(nullptr, L"open", item.szUrl, nullptr, nullptr, SW_SHOW);
          }
       }
       return TRUE;
@@ -204,11 +203,11 @@ static INT_PTR CALLBACK About_LicenseDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM
    return FALSE;
 }
 
-static bool GetWinMuteVersion(tstring& versNumber)
+static bool GetWinMuteVersion(std::wstring& versNumber)
 {
    bool success = false;
    DWORD dummy;
-   TCHAR szFileName[MAX_PATH];
+   wchar_t szFileName[MAX_PATH];
    GetModuleFileName(NULL, szFileName, sizeof(szFileName)/sizeof(szFileName[0]));
    DWORD versSize = GetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL, szFileName, &dummy);
    LPVOID versData = malloc(versSize);
@@ -221,16 +220,16 @@ static bool GetWinMuteVersion(tstring& versNumber)
             versData)) {
          VS_FIXEDFILEINFO *pvi;
          UINT pviLen = sizeof(*pvi);
-         if (VerQueryValue(
+         if (VerQueryValueW(
                versData,
-               _T("\\"),
+               L"\\",
                reinterpret_cast<LPVOID*>(&pvi),
                &pviLen)) {
-            TCHAR buf[30];
-            StringCchPrintf(
+            wchar_t buf[50];
+            StringCchPrintfW(
                buf,
                ARRAY_SIZE(buf),
-               _T("%d.%d.%d.%d"),
+               L"%d.%d.%d.%d",
                pvi->dwProductVersionMS >> 16,
                pvi->dwFileVersionMS & 0xFFFF,
                pvi->dwFileVersionLS >> 16,
@@ -255,8 +254,8 @@ INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 
       dlgData->hTabCtrl = GetDlgItem(hDlg, IDC_ABOUT_TAB);
 
-      InsertTabItem(dlgData->hTabCtrl, ABOUT_TAB_GENERAL, _T("WinMute"));
-      InsertTabItem(dlgData->hTabCtrl, ABOUT_TAB_LICENSE, _T("License"));
+      InsertTabItem(dlgData->hTabCtrl, ABOUT_TAB_GENERAL, L"WinMute");
+      InsertTabItem(dlgData->hTabCtrl, ABOUT_TAB_LICENSE, L"License");
 
       dlgData->hTabs[ABOUT_TAB_GENERAL] = CreateDialog(
          nullptr,
@@ -277,10 +276,10 @@ INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
       SwitchTab(dlgData, dlgData->hTabs[ABOUT_TAB_GENERAL]);
 
       HWND hTitle = GetDlgItem(hDlg, IDC_ABOUT_TITLE);
-      tstring progName = _T("WinMute");
-      tstring progVers = _T("WinMute");
+      std::wstring progName{ L"WinMute" };
+      std::wstring progVers{ L"WinMute" };
       if (GetWinMuteVersion(progVers)) {
-         progName = tstring(_T("WinMute ")) + progVers;
+         progName = std::wstring{ L"WinMute " } + progVers;
          Static_SetText(hTitle, progName.c_str());
       }
 
@@ -300,7 +299,7 @@ INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
       font.lfClipPrecision = CLIP_STROKE_PRECIS | CLIP_MASK | CLIP_TT_ALWAYS | CLIP_LH_ANGLES;
       font.lfQuality = CLEARTYPE_QUALITY;
       font.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
-      lstrcpy(font.lfFaceName, _T("Segoe UI"));
+      wcscpy_s(font.lfFaceName, L"Segoe UI");
 
       dlgData->hTitleFont = CreateFontIndirect(&font);
       SendMessage(
diff --git a/WinMute/BaseTypes.h b/WinMute/BaseTypes.h
deleted file mode 100644 (file)
index 4d9f4aa..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- WinMute
-           Copyright (c) 2022, Alexander Steinhoefer
-
------------------------------------------------------------------------------
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-    * Redistributions of source code must retain the above copyright notice,
-      this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above copyright
-      notice, this list of conditions and the following disclaimer in the
-      documentation and/or other materials provided with the distribution.
-
-    * Neither the name of the author nor the names of its contributors may
-      be used to endorse or promote products derived from this software
-      without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
-*/
-
-#pragma once
-
-#include <string>
-#include <string_view>
-
-#include <tchar.h>
-
-using tstring = std::basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR>>;
-using tstring_view = std::basic_string_view<TCHAR>;
-
index ba55e3246a6571db7614a710ff9dbe151057e874..24a801052672487d9332d93a58705f1ef5a57072 100644 (file)
@@ -77,7 +77,7 @@ bool MuteControl::Init(HWND hParent, const TrayIcon *trayIcon)
 
 void MuteControl::SetMute(bool mute)
 {
-   WMLog::GetInstance().Write(_T("Manual muting: %s"), mute ? _T("on") : _T("off"));
+   WMLog::GetInstance().Write(L"Manual muting: %s", mute ? L"on" : L"off");
    winAudio_->SetMute(mute);
 }
 
@@ -86,18 +86,18 @@ void MuteControl::SaveMuteStatus()
    bool alreadySaved = false;
    for (const auto& conf : muteConfig_) {
       if (conf.shouldMute && conf.active) {
-         WMLog::GetInstance().Write(_T("Muting event already active. Skipping status save"));
+         WMLog::GetInstance().Write(L"Muting event already active. Skipping status save");
          alreadySaved = true;
          break;
       }
    }
    if (!alreadySaved) {
-      WMLog::GetInstance().Write(_T("Saving mute status"));
+      WMLog::GetInstance().Write(L"Saving mute status");
       winAudio_->SaveMuteStatus();
    }
 }
 
-void MuteControl::ShowNotification(const tstring& title, const tstring& text)
+void MuteControl::ShowNotification(const std::wstring& title, const std::wstring& text)
 {
    if (notificationsEnabled_ && trayIcon_ != nullptr) {
       trayIcon_->ShowPopup(title, text);
@@ -113,22 +113,22 @@ void MuteControl::RestoreVolume()
 {
    WMLog& log = WMLog::GetInstance();
    if (!restoreVolume_) {
-      log.Write(_T("Volume Restore has been disabled"));
+      log.Write(L"Volume Restore has been disabled");
       return;
    }
    bool restore = true;
    for (const auto& conf : muteConfig_) {
       if (conf.shouldMute && conf.active) {
-         log.Write(_T("Skipping restore since other mute event is currently active"));
+         log.Write(L"Skipping restore since other mute event is currently active");
          restore = false;
          break;
       }
    }
    if (restore) {
-      log.Write(_T("Restoring previous mute state"));
+      log.Write(L"Restoring previous mute state");
       ShowNotification(
-         _T("Volume restored"),
-         _T("All endpoints have been restored to their previous configuration"));
+         L"Volume restored",
+         L"All endpoints have been restored to their previous configuration");
       winAudio_->RestoreMuteStatus();
    }
 }
@@ -219,10 +219,10 @@ void MuteControl::NotifyRestoreCondition(int type, bool active)
       SaveMuteStatus();
       muteConfig_[type].active = active;
       if (muteConfig_[type].shouldMute) {
-         WMLog::GetInstance().Write(_T("Muting workstation"));
+         WMLog::GetInstance().Write(L"Muting workstation");
          ShowNotification(
-            _T("Muting workstation"),
-            _T("All endpoints have been muted"));
+            L"Muting workstation",
+            L"All endpoints have been muted");
          winAudio_->SetMute(true);
       }
    } else {
@@ -237,30 +237,30 @@ void MuteControl::NotifyRestoreCondition(int type, bool active)
 
 void MuteControl::NotifyWorkstationLock(bool active)
 {
-   WMLog::GetInstance().Write(_T("Mute Event: Workstation Lock %s"),
-                              active ? _T("start") : _T("stop"));
+   WMLog::GetInstance().Write(L"Mute Event: Workstation Lock %s",
+                              active ? L"start" : L"stop");
    NotifyRestoreCondition(MuteTypeWorkstationLock, active);
 }
 
 void MuteControl::NotifyScreensaver(bool active)
 {
-   WMLog::GetInstance().Write(_T("Mute Event: Screensaver %s"),
-                              active ? _T("start") : _T("stop"));
+   WMLog::GetInstance().Write(L"Mute Event: Screensaver %s",
+                              active ? L"start" : L"stop");
    NotifyRestoreCondition(MuteTypeScreensaverActive, active);
 }
 
 void MuteControl::NotifyRemoteSession(bool active)
 {
-   WMLog::GetInstance().Write(_T("Mute Event: Remote Session %s"),
-                              active ? _T("start") : _T("stop"));
+   WMLog::GetInstance().Write(L"Mute Event: Remote Session %s",
+                              active ? L"start" : L"stop");
    NotifyRestoreCondition(MuteTypeRemoteSession, active);
 }
 
 void MuteControl::NotifyDisplayStandby(bool active)
 {
    if (displayWasOffOnce_ || active) {
-      WMLog::GetInstance().Write(_T("Mute Event: Display Standby %s"),
-                                 active ? _T("start") : _T("stop"));
+      WMLog::GetInstance().Write(L"Mute Event: Display Standby %s",
+                                 active ? L"start" : L"stop");
       NotifyRestoreCondition(MuteTypeDisplayStandby, active);
       displayWasOffOnce_ = true;
    }
@@ -268,7 +268,7 @@ void MuteControl::NotifyDisplayStandby(bool active)
 
 void MuteControl::NotifyLogout()
 {
-   WMLog::GetInstance().Write(_T("Mute Event: Logout start"));
+   WMLog::GetInstance().Write(L"Mute Event: Logout start");
    if (muteConfig_[MuteTypeLogout].shouldMute) {
       winAudio_->SetMute(true);
    }
@@ -276,7 +276,7 @@ void MuteControl::NotifyLogout()
 
 void MuteControl::NotifySuspend(bool /*active*/)
 {
-   WMLog::GetInstance().Write(_T("Mute Event: Suspend start"));
+   WMLog::GetInstance().Write(L"Mute Event: Suspend start");
    if (muteConfig_[MuteTypeSuspend].shouldMute) {
       winAudio_->SetMute(true);
    }
@@ -284,7 +284,7 @@ void MuteControl::NotifySuspend(bool /*active*/)
 
 void MuteControl::NotifyShutdown()
 {
-   WMLog::GetInstance().Write(_T("Mute Event: Shutdown start"));
+   WMLog::GetInstance().Write(L"Mute Event: Shutdown start");
    if (muteConfig_[MuteTypeShutdown].shouldMute) {
       winAudio_->SetMute(true);
    }
index fd5648826381d17c33ac1f31dc47ea77a1c0f5f7..75f492e76cec960a567a5608ef6590172d9f0e00 100644 (file)
@@ -98,5 +98,5 @@ private:
    void NotifyRestoreCondition(int type, bool active);
    void SaveMuteStatus();
    void RestoreVolume();
-   void ShowNotification(const tstring& title, const tstring& text);
+   void ShowNotification(const std::wstring& title, const std::wstring& text);
 };
index 65d97a3891491d6b5cc231182fd91e779bfc1259..ae6946ff075fe7c75db616475dcfa0e0cbac8846 100644 (file)
@@ -158,8 +158,8 @@ bool QuietHoursTimer::LoadFromSettings(const WMSettings& settings)
             hParent_,
             hglobInstance,
             PROGRAM_NAME,
-            _T("Quiet Hours Start"),
-            _T("Failed to register quiet hours start with windows timer system"),
+            L"Quiet Hours Start",
+            L"Failed to register quiet hours start with windows timer system",
             TDCBF_OK_BUTTON,
             TD_ERROR_ICON,
             nullptr);
@@ -192,8 +192,8 @@ bool QuietHoursTimer::SetStart()
          hParent_,
          hglobInstance,
          PROGRAM_NAME,
-         _T("Quiet Hours Start"),
-         _T("Failed to register quiet hours start with windows timer system"),
+         L"Quiet Hours Start",
+         L"Failed to register quiet hours start with windows timer system",
          TDCBF_OK_BUTTON,
          TD_ERROR_ICON,
          nullptr);
@@ -227,8 +227,8 @@ bool QuietHoursTimer::SetEnd()
          hParent_,
          hglobInstance,
          PROGRAM_NAME,
-         _T("Quiet Hours Stop"),
-         _T("Failed to register end of quiet hours with windows timer system"),
+         L"Quiet Hours Stop",
+         L"Failed to register end of quiet hours with windows timer system",
          TDCBF_OK_BUTTON,
          TD_ERROR_ICON,
          nullptr);
index 1bfad0c9a5ee4043dbb84dbf35b4d01d7ef6c39f..c8b0d3637db70f97b0772095a5daf96b0ca8b47e 100644 (file)
@@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
 
 extern HINSTANCE hglobInstance;
 
-static LPCTSTR SCRSVER_NOTIFY_WND_CLASS = _T("LXS_WinMuteScreensaverNotifyClass");
+static const wchar_t *SCRSVER_NOTIFY_WND_CLASS = L"LXS_WinMuteScreensaverNotifyClass";
 
 #define SCRSV_TIMER_ID 1
 
@@ -109,10 +109,10 @@ bool ScreensaverNotifier::Init()
 
 bool ScreensaverNotifier::InitWindow()
 {
-   hWnd_ = CreateWindowEx(
+   hWnd_ = CreateWindowExW(
       WS_EX_TOOLWINDOW,
       SCRSVER_NOTIFY_WND_CLASS,
-      _T("LXS_WinMute_ScreensaverNotify"),
+      L"LXS_WinMute_ScreensaverNotify",
       WS_POPUP,
       0, 0, 0, 0,
       NULL,
@@ -120,7 +120,7 @@ bool ScreensaverNotifier::InitWindow()
       hglobInstance,
       this);
    if (hWnd_ == nullptr) {
-      PrintWindowsError(_T("CreateWindow"));
+      PrintWindowsError(L"CreateWindow");
       return false;
    }
    ShowWindow(hWnd_, SW_HIDE);
@@ -129,9 +129,9 @@ bool ScreensaverNotifier::InitWindow()
 
 bool ScreensaverNotifier::InitWindowMessage()
 {
-   hookWndMsg_ = RegisterWindowMessage(_T("WinMuteScreenSaveNotifyMsg"));
+   hookWndMsg_ = RegisterWindowMessageW(L"WinMuteScreenSaveNotifyMsg");
    if (hookWndMsg_ == 0) {
-      PrintWindowsError(_T("RegisterWindowMessage"));
+      PrintWindowsError(L"RegisterWindowMessage");
       return false;
    }
    return true;
@@ -140,13 +140,8 @@ bool ScreensaverNotifier::InitWindowMessage()
 bool ScreensaverNotifier::InitHook32()
 {
    bool success = false;
-#ifdef _UNICODE
    wchar_t commandLine[MAX_PATH + 1];
    swprintf_s(commandLine, L"/msgId:%d", hookWndMsg_);
-#else
-   char commandLine[MAX_PATH + 1];
-   sprintf_s(commandLine, "/msgId:%d", hookWndMsg_));
-#endif
 
    JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobInfo;
    ZeroMemory(&jobInfo, sizeof(jobInfo));
@@ -159,16 +154,16 @@ bool ScreensaverNotifier::InitHook32()
 
    hJob_ = CreateJobObject(NULL, NULL);
    if (hJob_ == nullptr) {
-      PrintWindowsError(_T("CreateJobObject"), GetLastError());
+      PrintWindowsError(L"CreateJobObject", GetLastError());
    } else if (SetInformationJobObject(
       hJob_,
       JobObjectExtendedLimitInformation,
       &jobInfo,
       sizeof(jobInfo)) == FALSE) {
-      PrintWindowsError(_T("SetInformationJobObject"), GetLastError());
+      PrintWindowsError(L"SetInformationJobObject", GetLastError());
       CloseHandle(hJob_);
-   } else if (CreateProcess(
-         _T(".\\ScreensaverProxy32.exe"),
+   } else if (CreateProcessW(
+         L".\\ScreensaverProxy32.exe",
          commandLine,
          NULL,
          NULL,
@@ -178,12 +173,12 @@ bool ScreensaverNotifier::InitHook32()
          NULL,
          &startupInfo,
          &procInfo) == FALSE) {
-      PrintWindowsError(_T("CreateProcess"));
+      PrintWindowsError(L"CreateProcess");
       CloseHandle(hJob_);
       hJob_ = nullptr;
    } else {
       if (AssignProcessToJobObject(hJob_, procInfo.hProcess) == FALSE) {
-         PrintWindowsError(_T("AssignProcessToJobObject"), GetLastError());
+         PrintWindowsError(L"AssignProcessToJobObject", GetLastError());
          CloseHandle(hJob_);
          hJob_ = nullptr;
       } else {
@@ -198,9 +193,9 @@ bool ScreensaverNotifier::InitHook32()
 bool ScreensaverNotifier::InitHookDll()
 {
    if (hookDll_ == nullptr) {
-      hookDll_ = LoadLibrary(_T("ScreensaverNotify"));
+      hookDll_ = LoadLibraryW(L"ScreensaverNotify");
       if (hookDll_ == nullptr) {
-         PrintWindowsError(_T("LoadLibrary"));
+         PrintWindowsError(L"LoadLibrary");
       } else {
          regHook_ = reinterpret_cast<RegisterHook>(
             GetProcAddress(hookDll_, "RegisterScreensaverHook"));
@@ -224,7 +219,7 @@ bool ScreensaverNotifier::RegisterWindowClass()
    wc.lpszClassName = SCRSVER_NOTIFY_WND_CLASS;
 
    if (!RegisterClass(&wc)) {
-      PrintWindowsError(_T("RegisterClass"));
+      PrintWindowsError(L"RegisterClass");
       return false;
    }
    return true;
@@ -280,7 +275,7 @@ void ScreensaverNotifier::StartScreensaverPollTimer(bool start)
             1000,
             nullptr,
             TIMERV_DEFAULT_COALESCING) == 0) {
-         PrintWindowsError(_T("SetCoalescableTimer"));
+         PrintWindowsError(L"SetCoalescableTimer");
       }
    } else {
       KillTimer(hWnd_, SCRSV_TIMER_ID);
@@ -299,7 +294,7 @@ bool ScreensaverNotifier::IsScreensaverRunning()
          0,
          &isRunning,
          FALSE) == FALSE) {
-      PrintWindowsError(_T("SystemParametersInfo"));
+      PrintWindowsError(L"SystemParametersInfo");
       return false;
    }
    return isRunning != 0;
index 7092bb4f89458a8effa5087dd09a42be29d163b2..e52305357e8ca7792ec355cdc8db76f41a6fc34a 100644 (file)
@@ -64,14 +64,14 @@ extern INT_PTR CALLBACK Settings_WifiDlgProc(HWND, UINT, WPARAM, LPARAM);
 
 extern HINSTANCE hglobInstance;
 
-static void InsertTabItem(HWND hTabCtrl, UINT id, const TCHAR* itemName)
+static void InsertTabItem(HWND hTabCtrl, UINT id, const wchar_t *itemName)
 {
    constexpr int bufSize = 50;
-   TCHAR buf[bufSize];
+   wchar_t buf[bufSize];
    TC_ITEM tcItem;
    ZeroMemory(&tcItem, sizeof(tcItem));
    tcItem.mask |= TCIF_TEXT;
-   StringCchCopy(buf, bufSize, itemName);
+   StringCchCopyW(buf, bufSize, itemName);
    tcItem.pszText = buf;
    tcItem.cchTextMax = bufSize;
 
@@ -104,7 +104,7 @@ static void ResizeTabs(HWND hTabCtrl, HWND* hTabs, int tabCount)
 
    HDWP hdwp = BeginDeferWindowPos(tabCount);
    if (hdwp == NULL) {
-      PrintWindowsError(_T("BeginDeferWindowPos"), GetLastError());
+      PrintWindowsError(L"BeginDeferWindowPos", GetLastError());
    } else {
       for (int i = 0; i < tabCount; ++i) {
          HDWP newHdwp = DeferWindowPos(
@@ -117,7 +117,7 @@ static void ResizeTabs(HWND hTabCtrl, HWND* hTabs, int tabCount)
             tabCtrlRect.bottom - tabCtrlRect.top,
             0);
          if (newHdwp == NULL) {
-            PrintWindowsError(_T("DeferWindowPos"), GetLastError());
+            PrintWindowsError(L"DeferWindowPos", GetLastError());
             break;
          } else {
             hdwp = newHdwp;
@@ -140,11 +140,11 @@ INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPar
       
       dlgData->hTabCtrl = GetDlgItem(hDlg, IDC_SETTINGS_TAB);
 
-      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_GENERAL, _T("General"));
-      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_MUTE, _T("Mute"));
-      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_QUIETHOURS, _T("Quiet Hours"));
-      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_WIFI, _T("WLAN"));
-      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_BLUETOOTH, _T("Bluetooth"));
+      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_GENERAL, L"General");
+      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_MUTE, L"Mute");
+      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_QUIETHOURS, L"Quiet Hours");
+      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_WIFI, L"WLAN");
+      InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_BLUETOOTH, L"Bluetooth");
 
       dlgData->hTabs[SETTINGS_TAB_GENERAL] = CreateDialogParam(
          hglobInstance,
index b2da0859c7e5ffb5377b80844ed8aa6cec1a7c94..854886d0084cb3e12bc30a7aedcdf5c026db4e66 100644 (file)
@@ -36,10 +36,10 @@ POSSIBILITY OF SUCH DAMAGE.
 static constexpr int BT_DEV_NAME_MAX_LEN = 100;
 
 struct BtDeviceName {
-   tstring devName;
+   std::wstring devName;
 };
 
-static bool GetPairedBtAudioDevices(std::vector<tstring>& devices)
+static bool GetPairedBtAudioDevices(std::vector<std::wstring>& devices)
 {
    auto& log = WMLog::GetInstance();
 
@@ -78,20 +78,20 @@ static INT_PTR CALLBACK Settings_BluetoothAddDlgProc(HWND hDlg, UINT msg, WPARAM
       SetWindowLongPtr(hDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(btDeviceData));
 
       if (btDeviceData->devName.length() == 0) {
-         if (!SetWindowText(hDlg, _T("Add Bluetooth device"))) {
-             PrintWindowsError(_T("SetWindowText"), GetLastError());
+         if (!SetWindowTextW(hDlg, L"Add Bluetooth device")) {
+             PrintWindowsError(L"SetWindowText", GetLastError());
             return FALSE;
          }
       } else {
-         if (!SetWindowText(hDlg, _T("Edit Bluetooth device"))
-             || !SetWindowText(GetDlgItem(hDlg, IDC_BT_DEVICE_NAME),
+         if (!SetWindowTextW(hDlg, L"Edit Bluetooth device")
+             || !SetWindowTextW(GetDlgItem(hDlg, IDC_BT_DEVICE_NAME),
                                btDeviceData->devName.c_str())) {
-            PrintWindowsError(_T("SetWindowText"), GetLastError());
+            PrintWindowsError(L"SetWindowText", GetLastError());
             return FALSE;
          }
       }
       // Fill Combobox
-      std::vector<tstring> registeredBtDevices;
+      std::vector<std::wstring> registeredBtDevices;
       if (GetPairedBtAudioDevices(registeredBtDevices)) {
          for (const auto& devName : registeredBtDevices) {
             ComboBox_AddString(hBtDevName, devName.c_str());
@@ -113,12 +113,12 @@ static INT_PTR CALLBACK Settings_BluetoothAddDlgProc(HWND hDlg, UINT msg, WPARAM
             EDITBALLOONTIP ebt;
             ZeroMemory(&ebt, sizeof(ebt));
             ebt.cbStruct = sizeof(ebt);
-            ebt.pszText = _T("Please enter a Bluetooth device name");
-            ebt.pszTitle = _T("Bluetooth Device Name");
+            ebt.pszText = L"Please enter a Bluetooth device name";
+            ebt.pszTitle = L"Bluetooth Device Name";
             ebt.ttiIcon = TTI_INFO;
             Edit_ShowBalloonTip(hDevName, &ebt);
          } else {
-            TCHAR devNameBuf[BT_DEV_NAME_MAX_LEN + 1];
+            wchar_t devNameBuf[BT_DEV_NAME_MAX_LEN + 1];
             BtDeviceName* btDevName = reinterpret_cast<BtDeviceName*>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
             if (btDevName != nullptr) {
                Edit_GetText(hDevName, devNameBuf, ARRAY_SIZE(devNameBuf));
@@ -142,12 +142,12 @@ static INT_PTR CALLBACK Settings_BluetoothAddDlgProc(HWND hDlg, UINT msg, WPARAM
    return FALSE;
 }
 
-static std::vector<tstring> ExportBluetoothDeviceList(HWND hList)
+static std::vector<std::wstring> ExportBluetoothDeviceList(HWND hList)
 {
-   std::vector<tstring> items;
+   std::vector<std::wstring> items;
    DWORD itemCount = ListBox_GetCount(hList);
    for (DWORD i = 0; i < itemCount; ++i) {
-      TCHAR textBuf[BT_DEV_NAME_MAX_LEN + 1] = { 0 };
+      wchar_t textBuf[BT_DEV_NAME_MAX_LEN + 1] = { 0 };
       DWORD textLen = ListBox_GetTextLen(hList, i);
       if (textLen < ARRAY_SIZE(textBuf)) {
          ListBox_GetText(hList, i, textBuf);
@@ -241,7 +241,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
                hDlg,
                Settings_BluetoothAddDlgProc,
                reinterpret_cast<LPARAM>(&btDeviceName)) == 0) {
-            std::vector<tstring> devices = ExportBluetoothDeviceList(GetDlgItem(hDlg, IDC_BLUETOOTH_LIST));
+            std::vector<std::wstring> devices = ExportBluetoothDeviceList(GetDlgItem(hDlg, IDC_BLUETOOTH_LIST));
             if (std::find(begin(devices), end(devices), btDeviceName.devName) == end(devices)) {
                ListBox_AddString(
                   GetDlgItem(hDlg, IDC_BLUETOOTH_LIST),
@@ -257,9 +257,9 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
          WPARAM sel = ListBox_GetCurSel(hList);
          if (sel != LB_ERR) {
             int len = ListBox_GetTextLen(hList, sel);
-            TCHAR* textBuf = NULL;
+            wchar_t* textBuf = NULL;
             if (len != LB_ERR) {
-               if ((textBuf = new TCHAR[static_cast<size_t>(len) + 1]) != NULL) {
+               if ((textBuf = new wchar_t[static_cast<size_t>(len) + 1]) != NULL) {
                   ListBox_GetText(hList, sel, textBuf);
 
                   BtDeviceName btDevName;
@@ -272,7 +272,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
                         hDlg,
                         Settings_BluetoothAddDlgProc,
                         reinterpret_cast<LPARAM>(&btDevName)) == 0) {
-                     std::vector<tstring> networks = ExportBluetoothDeviceList(GetDlgItem(hDlg, IDC_WIFI_LIST));
+                     std::vector<std::wstring> networks = ExportBluetoothDeviceList(GetDlgItem(hDlg, IDC_WIFI_LIST));
                      if (std::find(begin(networks), end(networks), btDevName.devName) == end(networks)) {
                         ListBox_InsertString(hList, sel, btDevName.devName.c_str());
                         ListBox_DeleteString(hList, sel + 1);
@@ -305,7 +305,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
    }
    case WM_SAVESETTINGS: {
       WMSettings* settings = reinterpret_cast<WMSettings*>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
-      std::vector<tstring> devices = ExportBluetoothDeviceList(GetDlgItem(hDlg, IDC_BLUETOOTH_LIST));
+      std::vector<std::wstring> devices = ExportBluetoothDeviceList(GetDlgItem(hDlg, IDC_BLUETOOTH_LIST));
       settings->StoreBluetoothDevices(devices);
 
       DWORD checked = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE));
index 47477d9e8ecfb1b5ecc9f14067ccc52d62da02db..36274b7129d0e6043c1c03e0ab856c4b4c6e6dc1 100644 (file)
@@ -64,8 +64,8 @@ INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA
          Button_Enable(GetDlgItem(hDlg, IDC_OPENLOG), checked == BST_CHECKED);
       } else if (LOWORD(wParam) == IDC_OPENLOG) {
          WMLog& log = WMLog::GetInstance();
-         const std::string filePath = log.GetLogFilePath().c_str();
-         ShellExecuteA(NULL, "open", filePath.c_str(), NULL, NULL, SW_SHOW);
+         const std::wstring filePath = log.GetLogFilePath().c_str();
+         ShellExecuteW(NULL, L"open", filePath.c_str(), NULL, NULL, SW_SHOW);
       }
       return 0;
    }
index 35e99d275c375bfcb6aa76fac1a456b8098e218a..80238b911220bb121e716cb94463468cbdc9360e 100644 (file)
@@ -60,9 +60,9 @@ static bool SaveQuietHours(
             nullptr,
             nullptr,
             PROGRAM_NAME,
-            _T("Invalid time range"),
-            _T("Can't start and stop at the same time.\n")
-            _T("Please correct your time range.\n"),
+            L"Invalid time range",
+            L"Can't start and stop at the same time.\n"
+            L"Please correct your time range.\n",
             TDCBF_OK_BUTTON,
             TD_WARNING_ICON,
             nullptr);
@@ -82,8 +82,8 @@ static bool SaveQuietHours(
          nullptr,
          nullptr,
          PROGRAM_NAME,
-         _T("Failed to save quiet hours settings"),
-         _T("Something went wrong while saving your settings."),
+         L"Failed to save quiet hours settings",
+         L"Something went wrong while saving your settings.",
          TDCBF_OK_BUTTON,
          TD_ERROR_ICON,
          nullptr);
index f0eaf9c10e400443e1f38e619ad36d45a300751a..552e0a6de66fefc32c4c987d5640c96e001cf268 100644 (file)
@@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
 static constexpr int SSID_MAX_LEN = 32;
 
 struct WiFiData {
-   tstring ssidName;
+   std::wstring ssidName;
 };
 
 INT_PTR CALLBACK Settings_WifiAddDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -51,16 +51,14 @@ INT_PTR CALLBACK Settings_WifiAddDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA
       SetWindowLongPtr(hDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(wifiData));
 
       if (wifiData->ssidName.length() == 0) {
-         if (!SetWindowText(hDlg, _T("Add WiFi network"))) {
-            PrintWindowsError(_T("SetWindowText"), GetLastError());
+         if (!SetWindowTextW(hDlg, L"Add WiFi network")) {
+            PrintWindowsError(L"SetWindowText", GetLastError());
             return FALSE;
          }
       } else {
-         if (!SetWindowText(hDlg, _T("Edit WiFi network"))
-            || !SetWindowText(
-               GetDlgItem(hDlg, IDC_WIFI_NAME),
-               wifiData->ssidName.c_str())) {
-            PrintWindowsError(_T("SetWindowText"), GetLastError());
+         if (!SetWindowTextW(hDlg, L"Edit WiFi network")
+             || !SetWindowTextW(GetDlgItem(hDlg, IDC_WIFI_NAME), wifiData->ssidName.c_str())) {
+            PrintWindowsError(L"SetWindowText", GetLastError());
             return FALSE;
          }
       }
@@ -79,12 +77,12 @@ INT_PTR CALLBACK Settings_WifiAddDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA
             EDITBALLOONTIP ebt;
             ZeroMemory(&ebt, sizeof(ebt));
             ebt.cbStruct = sizeof(ebt);
-            ebt.pszText = _T("Please enter a SSID/WIFI name");
-            ebt.pszTitle = _T("SSID Name");
+            ebt.pszText = L"Please enter a SSID/WIFI name";
+            ebt.pszTitle = L"SSID Name";
             ebt.ttiIcon = TTI_INFO;
             Edit_ShowBalloonTip(hSsid, &ebt);
          } else {
-            TCHAR ssidBuf[SSID_MAX_LEN + 1];
+            wchar_t ssidBuf[SSID_MAX_LEN + 1];
             WiFiData* wifiData = reinterpret_cast<WiFiData*>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
             if (wifiData != nullptr) {
                Edit_GetText(hSsid, ssidBuf, ARRAY_SIZE(ssidBuf));
@@ -107,12 +105,12 @@ INT_PTR CALLBACK Settings_WifiAddDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA
    return FALSE;
 }
 
-static std::vector<tstring> ExportSsidListItems(HWND hList)
+static std::vector<std::wstring> ExportSsidListItems(HWND hList)
 {
-   std::vector<tstring> items;
+   std::vector<std::wstring> items;
    DWORD itemCount = ListBox_GetCount(hList);
    for (DWORD i = 0; i < itemCount; ++i) {
-      TCHAR textBuf[SSID_MAX_LEN + 1] = { 0 };
+      wchar_t textBuf[SSID_MAX_LEN + 1] = { 0 };
       DWORD textLen = ListBox_GetTextLen(hList, i);
       if (textLen < ARRAY_SIZE(textBuf)) {
          ListBox_GetText(hList, i, textBuf);
@@ -152,7 +150,6 @@ INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
       enabled = settings->QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST);
       Button_SetCheck(GetDlgItem(hDlg, IDC_IS_PERMITLIST),
                       enabled ? BST_CHECKED : BST_UNCHECKED);
-      
 
       Button_Enable(GetDlgItem(hDlg, IDC_WIFI_EDIT), FALSE);
       Button_Enable(GetDlgItem(hDlg, IDC_WIFI_REMOVE), FALSE);
@@ -201,7 +198,7 @@ INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
                hDlg,
                Settings_WifiAddDlgProc,
                reinterpret_cast<LPARAM>(&wifiData)) == 0) {
-            std::vector<tstring> networks = ExportSsidListItems(GetDlgItem(hDlg, IDC_WIFI_LIST));
+            std::vector<std::wstring> networks = ExportSsidListItems(GetDlgItem(hDlg, IDC_WIFI_LIST));
             if (std::find(begin(networks), end(networks), wifiData.ssidName) == end(networks)) {
                ListBox_AddString(
                   GetDlgItem(hDlg, IDC_WIFI_LIST),
@@ -217,9 +214,9 @@ INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
          WPARAM sel = ListBox_GetCurSel(hList);
          if (sel != LB_ERR) {
             int len = ListBox_GetTextLen(hList, sel);
-            TCHAR * textBuf = NULL;
+            wchar_t *textBuf = NULL;
             if (len != LB_ERR) {
-               if ((textBuf = new TCHAR[static_cast<size_t>(len) + 1]) != NULL) {
+               if ((textBuf = new wchar_t[static_cast<size_t>(len) + 1]) != NULL) {
                   ListBox_GetText(hList, sel, textBuf);
 
                   WiFiData wifiData;
@@ -232,7 +229,7 @@ INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
                         hDlg,
                         Settings_WifiAddDlgProc,
                         reinterpret_cast<LPARAM>(&wifiData)) == 0) {
-                     std::vector<tstring> networks = ExportSsidListItems(GetDlgItem(hDlg, IDC_WIFI_LIST));
+                     std::vector<std::wstring> networks = ExportSsidListItems(GetDlgItem(hDlg, IDC_WIFI_LIST));
                      if (std::find(begin(networks), end(networks), wifiData.ssidName) == end(networks)) {
                         ListBox_InsertString(hList, sel, wifiData.ssidName.c_str());
                         ListBox_DeleteString(hList, sel + 1);
@@ -264,7 +261,7 @@ INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
    }
    case WM_SAVESETTINGS: {
       WMSettings* settings = reinterpret_cast<WMSettings*>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
-      std::vector<tstring> networks = ExportSsidListItems(GetDlgItem(hDlg, IDC_WIFI_LIST));
+      std::vector<std::wstring> networks = ExportSsidListItems(GetDlgItem(hDlg, IDC_WIFI_LIST));
       settings->StoreWifiNetworks(networks);
 
       DWORD checked = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_WIFI_MUTE));
index 2dfaff659b4ee8330aa333b2044e97cc5d59b3c7..9d3001549e07b3b8a7615825396ac43a10a95b0b 100644 (file)
@@ -39,7 +39,7 @@ TrayIcon::TrayIcon() :
 }
 
 TrayIcon::TrayIcon(HWND hWnd, UINT trayID, HICON hIcon,
-                   const tstring& tooltip, bool show) :
+                   const std::wstring& tooltip, bool show) :
    initialized_(false),
    iconVisible_(false)
 {
@@ -47,7 +47,7 @@ TrayIcon::TrayIcon(HWND hWnd, UINT trayID, HICON hIcon,
 }
 
 void TrayIcon::Init(HWND hWnd, UINT trayID, HICON hIcon,
-                    const tstring& tooltip, bool show)
+                    const std::wstring& tooltip, bool show)
 {
    if (!hIcon) {
       hIcon_ = LoadIcon(0, IDI_APPLICATION);
@@ -123,7 +123,7 @@ void TrayIcon::ChangeIcon(HICON hNewIcon)
    return;
 }
 
-void TrayIcon::ChangeText(const tstring& tooltip)
+void TrayIcon::ChangeText(const std::wstring& tooltip)
 {
    tooltip_ = tooltip;
 
@@ -131,7 +131,7 @@ void TrayIcon::ChangeText(const tstring& tooltip)
       ChangeText();
 }
 
-void TrayIcon::ShowPopup(const tstring& title, const tstring& text) const
+void TrayIcon::ShowPopup(const std::wstring& title, const std::wstring& text) const
 {
    if (!initialized_) {
       TrayIconPopup popup;
index 0fbd9edc754eaf2aaa5e43253f9942fbd88f1483..610401afede28b12cf14664a0629f9be288580e2 100644 (file)
@@ -38,24 +38,24 @@ POSSIBILITY OF SUCH DAMAGE.
 #define WM_TRAYICON (WM_APP + 700)
 
 struct TrayIconPopup {
-   tstring title;
-   tstring text;
+   std::wstring title;
+   std::wstring text;
 };
 
 class TrayIcon {
 public:
    TrayIcon();
-   TrayIcon(HWND hWnd, UINT trayID, HICON hIcon, const tstring& tooltip,
+   TrayIcon(HWND hWnd, UINT trayID, HICON hIcon, const std::wstring& tooltip,
       bool show);
    ~TrayIcon();
-   void Init(HWND hWnd, UINT trayID, HICON hIcon, const tstring& tooltip,
+   void Init(HWND hWnd, UINT trayID, HICON hIcon, const std::wstring& tooltip,
       bool show);
    void Hide();
    void Show();
    bool IsShown() const { return iconVisible_; }
    void ChangeIcon(HICON hNewIcon);
-   void ChangeText(const tstring& tooltip);
-   void ShowPopup(const tstring& title, const tstring& text) const;
+   void ChangeText(const std::wstring& tooltip);
+   void ShowPopup(const std::wstring& title, const std::wstring& text) const;
 
 private:
    void DestroyTrayIcon();
@@ -70,5 +70,5 @@ private:
    UINT trayID_;
    HICON hIcon_;
    HWND hWnd_;
-   tstring tooltip_;
+   std::wstring tooltip_;
 };
index db61db2782c77aa58934c85547ff783bb3881bb7..924bcc213f337e5f79bd744d7310467ee4fa30ff 100644 (file)
@@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #include "Common.h"
 
-void PrintWindowsError(LPCWSTR lpszFunction, DWORD lastError)
+void PrintWindowsError(const wchar_t *functionName, DWORD lastError)
 {
    // Retrieve the system error message for the last-error code
    if (lastError == -1) {
@@ -41,26 +41,27 @@ void PrintWindowsError(LPCWSTR lpszFunction, DWORD lastError)
    }
 
    LPVOID lpMsgBuf;
-   if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-      FORMAT_MESSAGE_FROM_SYSTEM |
-      FORMAT_MESSAGE_IGNORE_INSERTS,
-      nullptr, lastError,
-      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-      reinterpret_cast<LPTSTR>(&lpMsgBuf), 0, nullptr) != 0) {
+   if (FormatMessage(
+         FORMAT_MESSAGE_ALLOCATE_BUFFER |
+         FORMAT_MESSAGE_FROM_SYSTEM |
+         FORMAT_MESSAGE_IGNORE_INSERTS,
+         nullptr, lastError,
+         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+         reinterpret_cast<wchar_t*>(&lpMsgBuf), 0, nullptr) != 0) {
       size_t displayBufSize =
-         ((size_t)lstrlen(static_cast<LPCTSTR>(lpMsgBuf)) +
-            (size_t)lstrlen(static_cast<LPCTSTR>(lpszFunction))
-            + 40) * sizeof(TCHAR);
+         (wcslen(static_cast<const wchar_t*>(lpMsgBuf))
+          + wcslen(static_cast<const wchar_t*>(functionName))
+          + 40) * sizeof(wchar_t);
       // Display the error message and exit the process
       LPVOID lpDisplayBuf = reinterpret_cast<LPVOID>(
          LocalAlloc(LMEM_ZEROINIT, displayBufSize));
       if (lpDisplayBuf) {
-         StringCchPrintf((LPTSTR)lpDisplayBuf,
+         StringCchPrintfW((LPTSTR)lpDisplayBuf,
             LocalSize(lpDisplayBuf),
-            _T("%s failed with error %u: %s"),
-            lpszFunction,
+            L"%s failed with error %u: %s",
+            functionName,
             lastError,
-            reinterpret_cast<TCHAR*>(lpMsgBuf));
+            reinterpret_cast<wchar_t*>(lpMsgBuf));
          TaskDialog(
             nullptr,
             nullptr,
index 0b5aa2aaa3559db102ffdeafb106c3efb1d39c83..1a66daa6107b37e047050a8e25e01044cb5448b3 100644 (file)
@@ -99,13 +99,13 @@ bool VistaAudio::LoadAllEndpoints()
 
       hr = audioEndpoints->Item(i, &device);
       if (FAILED(hr)) {
-         log.Write(_T("Failed to get audio endpoint #%d"), i);
+         log.Write(L"Failed to get audio endpoint #%d", i);
          continue;
       }
 
       hr = device->OpenPropertyStore(STGM_READ, &propStore);
       if (FAILED(hr)) {
-         log.Write(_T("Failed to open property store for audio endpoint #%d"), i);
+         log.Write(L"Failed to open property store for audio endpoint #%d", i);
          continue;
       }
 
@@ -113,10 +113,10 @@ bool VistaAudio::LoadAllEndpoints()
       PropVariantInit(&value);
       hr = propStore->GetValue(PKEY_Device_FriendlyName, &value);
       if (FAILED(hr)) {
-         log.Write(_T("Failed to get device name for audio endpoint #%d"), i);
+         log.Write(L"Failed to get device name for audio endpoint #%d", i);
          continue;
       }
-      log.Write(_T("Found audio endpoint \"%s\""), value.pwszVal);
+      log.Write(L"Found audio endpoint \"%s\"", value.pwszVal);
       StringCchCopy(ep->deviceName,
                     sizeof(ep->deviceName)/sizeof(ep->deviceName[0]),
                     value.pwszVal);
@@ -127,14 +127,14 @@ bool VistaAudio::LoadAllEndpoints()
       if (FAILED(device->Activate(
             __uuidof(IAudioSessionManager2), CLSCTX_INPROC_SERVER, nullptr,
             reinterpret_cast<LPVOID*>(&sessionManager2)))) {
-         log.Write(_T("Failed to retrieve audio session manager for \"%s\""),
+         log.Write(L"Failed to retrieve audio session manager for \"%s\"",
                    ep->deviceName);
          continue;
       }
 
       hr = sessionManager2->GetAudioSessionControl(nullptr, 0, &ep->sessionCtrl);
       if (FAILED(hr)) {
-         log.Write(_T("Failed to retrieve audio session manager for \"%s\""),
+         log.Write(L"Failed to retrieve audio session manager for \"%s\"",
             ep->deviceName);
          continue;
       }
@@ -149,7 +149,7 @@ bool VistaAudio::LoadAllEndpoints()
          __uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER,
          nullptr, reinterpret_cast<LPVOID*>(&ep->endpointVolume));
       if (FAILED(hr)) {
-         log.Write(_T("Failed to active endpoint volume for device \"%s\""),
+         log.Write(L"Failed to active endpoint volume for device \"%s\"",
                    ep->deviceName);
          continue;
       }
@@ -172,7 +172,7 @@ bool VistaAudio::Init(HWND hParent)
          __uuidof(MMDeviceEnumerator),
          nullptr,
          CLSCTX_INPROC_SERVER))) {
-      log.Write(_T("Failed to create instance of MMDeviceEnumerator"));
+      log.Write(L"Failed to create instance of MMDeviceEnumerator");
       return false;
    }
 
@@ -221,7 +221,7 @@ bool VistaAudio::AllEndpointsMuted()
       for (auto& e : endpoints_) {
          BOOL isMuted = FALSE;
          if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
-            log.Write(_T("Failed to get mute status for \"%s\""),
+            log.Write(L"Failed to get mute status for \"%s\"",
                e->deviceName);
             allMuted = false;
             break;
@@ -243,7 +243,7 @@ bool VistaAudio::SaveMuteStatus()
       for (auto& e : endpoints_) {
          BOOL isMuted = FALSE;
          if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
-            log.Write(_T("Failed to get mute status for \"%s\""),
+            log.Write(L"Failed to get mute status for \"%s\"",
                       e->deviceName);
             success = false;
          } else {
@@ -260,13 +260,13 @@ bool VistaAudio::RestoreMuteStatus()
    WMLog& log = WMLog::GetInstance();
 
    for (auto& e : endpoints_) {
-      log.Write(_T("Restoring: Mute %s for \"%s\""),
-                (e->wasMuted) ? _T("true") : _T("false"),
+      log.Write(L"Restoring: Mute %s for \"%s\"",
+                (e->wasMuted) ? L"true" : L"false",
                 e->deviceName);
       if (e->wasMuted != true) {
          if (FAILED(e->endpointVolume->SetMute(false, nullptr))) {
             log.Write(_T("Failed to restore mute status to %s for \"%s\""),
-                      (e->wasMuted) ? _T("true") : _T("false"),
+                      (e->wasMuted) ? L"true" : L"false",
                       e->deviceName);
             success = false;
          }
@@ -283,13 +283,13 @@ void VistaAudio::SetMute(bool mute)
       for (auto& e : endpoints_) {
          BOOL isMuted = !mute;
          if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
-            log.Write(_T("Failed to get mute status for \"%s\""),
+            log.Write(L"Failed to get mute status for \"%s\"",
                       e->deviceName);
          }
          if (!!isMuted != mute) {
             if (FAILED(e->endpointVolume->SetMute(mute, nullptr))) {
-               log.Write(_T("Failed to set mute status to %s for \"%s\""),
-                         (e->wasMuted) ? _T("true") : _T("false"),
+               log.Write(L"Failed to set mute status to %s for \"%s\"",
+                         (e->wasMuted) ? L"true" : L"false",
                          e->deviceName);
             }
          }
index ea1ec371d02d8aeb201f64973103ea0a6d5df1ae..920a5e9bf0f771e3165dc6c29234aace90b5509f 100644 (file)
@@ -129,9 +129,9 @@ HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnSessionDisconnected(
       TaskDialog(nullptr,
          nullptr,
          PROGRAM_NAME,
-         _T("The audio service has been shut down. "),
-         _T("WinMute is not able to recover from that condition.\n")
-         _T("Please try restarting the program"),
+         L"The audio service has been shut down. ",
+         L"WinMute is not able to recover from that condition.\n"
+         L"Please try restarting the program",
          TDCBF_OK_BUTTON,
          TD_WARNING_ICON,
          nullptr);
index fddb479f1bebf74c5f573ba8b9994bdf779e61c0..6d00ca908b632599be7cbb31b0898a750eba4207 100644 (file)
@@ -33,11 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #include "common.h"
 
-#ifdef UNICODE
-static bool OpenLogFile(const std::string& filePath, std::wofstream& logFile)
-#else
-static bool OpenLogFile(const std::string& filePath, std::ofstream& logFile)
-#endif
+static bool OpenLogFile(const std::wstring& filePath, std::wofstream& logFile)
 {
    logFile.open(filePath, std::ios::out | std::ios::app | std::ios::binary);
    return logFile.is_open();
@@ -61,18 +57,24 @@ WMLog::~WMLog()
    }
 }
 
-std::string WMLog::GetLogFilePath()
+std::wstring WMLog::GetLogFilePath()
 {
-   auto path = std::filesystem::temp_directory_path();
-   path /= _T("WinMute.log");
-   return path.string();
+   wchar_t tempPath[MAX_PATH + 1];
+   if (GetTempPathW(ARRAY_SIZE(tempPath), tempPath)) {
+      std::wstring path{ tempPath };
+      path += L"\\WinMute.log";
+      return path;
+   }
+   return std::wstring();
 }
 
 void WMLog::DeleteLogFile()
 {
-   auto p = GetLogFilePath();
-   logFile_.close();
-   DeleteFileA(p.c_str());
+   const auto logFilePath = GetLogFilePath();
+   if (logFile_.is_open()) {
+      logFile_.close();
+   }
+   DeleteFileW(logFilePath.c_str());
 }
 
 void WMLog::SetEnabled(bool enable)
@@ -96,46 +98,38 @@ void WMLog::SetEnabled(bool enable)
    }
 }
 
-void WMLog::WriteMessage(const TCHAR* msg)
+void WMLog::WriteMessage(const wchar_t* msg)
 {
    struct tm tm;
    auto now = std::chrono::system_clock::now();
    auto in_time_t = std::chrono::system_clock::to_time_t(now);
 
-#ifdef UNICODE
    std::wstringstream ss;
-#else
-   std::stringstream ss;
-#endif
    localtime_s(&tm, &in_time_t);
-   ss << _T("[") << std::put_time(&tm, _T("%Y-%m-%d %X")) << _T("] ")
-      << msg << _T("\n");
+   ss << L"[" << std::put_time(&tm, L"%Y-%m-%d %X") << L"] "
+      << msg << L"\n";
    const auto& logStr = ss.str();
    logFile_.write(logStr.c_str(), logStr.length());
    logFile_.flush();
 }
 
-void WMLog::Write(const TCHAR *fmt, ...)
+void WMLog::Write(const wchar_t *fmt, ...)
 {
    if (!enabled_) {
       return;
    }
 
-   TCHAR buf[200];
+   wchar_t buf[200];
    va_list ap;
    va_start(ap, fmt);
 
-#ifdef _UNICODE
    vswprintf_s(buf, fmt, ap);
-#else
-   snprintf(buf, ARRAY_SIZE(buf), fmt, ap);
-#endif
    WriteMessage(buf);
 
    va_end(ap);
 }
 
-void WMLog::WriteWindowsError(LPCWSTR lpszFunction, DWORD lastError)
+void WMLog::WriteWindowsError(const wchar_t *functionName, DWORD lastError)
 {
    // Retrieve the system error message for the last-error code
    if (lastError == -1) {
@@ -143,27 +137,29 @@ void WMLog::WriteWindowsError(LPCWSTR lpszFunction, DWORD lastError)
    }
 
    LPVOID lpMsgBuf;
-   if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-      FORMAT_MESSAGE_FROM_SYSTEM |
-      FORMAT_MESSAGE_IGNORE_INSERTS,
-      nullptr, lastError,
-      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-      reinterpret_cast<LPTSTR>(&lpMsgBuf), 0, nullptr) != 0) {
+   if (FormatMessage(
+         FORMAT_MESSAGE_ALLOCATE_BUFFER
+         | FORMAT_MESSAGE_FROM_SYSTEM
+         | FORMAT_MESSAGE_IGNORE_INSERTS,
+         nullptr, lastError,
+         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+         reinterpret_cast<wchar_t*>(&lpMsgBuf), 0, nullptr) != 0) {
       size_t displayBufSize =
-         ((size_t)lstrlen(static_cast<LPCTSTR>(lpMsgBuf)) +
-            (size_t)lstrlen(static_cast<LPCTSTR>(lpszFunction))
-            + 40) * sizeof(TCHAR);
+         (wcslen(static_cast<const wchar_t*>(lpMsgBuf))
+          + wcslen(static_cast<const wchar_t*>(functionName))
+          + 40) * sizeof(wchar_t);
       // Display the error message and exit the process
       LPVOID lpDisplayBuf = reinterpret_cast<LPVOID>(
          LocalAlloc(LMEM_ZEROINIT, displayBufSize));
       if (lpDisplayBuf) {
-         StringCchPrintf((LPTSTR)lpDisplayBuf,
+         StringCchPrintfW(
+            reinterpret_cast<wchar_t*>(lpDisplayBuf),
             LocalSize(lpDisplayBuf),
-            _T("%s failed with error %u: %s"),
-            lpszFunction,
+            L"%s failed with error %u: %s",
+            functionName,
             lastError,
-            reinterpret_cast<TCHAR*>(lpMsgBuf));
-         WriteMessage(static_cast<LPCTSTR>(lpMsgBuf));
+            reinterpret_cast<wchar_t*>(lpMsgBuf));
+         WriteMessage(static_cast<const wchar_t*>(lpMsgBuf));
          LocalFree(lpDisplayBuf);
       }
       LocalFree(lpMsgBuf);
index 16c0d137b7615d2b92494b5ac861061248e8c1c9..afcdd985d2dd09b65ab8492deb0f06b6aab147d8 100644 (file)
@@ -39,11 +39,11 @@ class WMLog {
 public:
    static WMLog& GetInstance();
 
-   void Write(const TCHAR* fmt, ...);
-   void WriteWindowsError(LPCWSTR lpszFunction, DWORD errorCode = -1);
+   void Write(const wchar_t* fmt, ...);
+   void WriteWindowsError(const wchar_t *functionName, DWORD errorCode = -1);
 
    void SetEnabled(bool enable);
-   std::string GetLogFilePath();
+   std::wstring GetLogFilePath();
 
 private:
    WMLog();
@@ -51,13 +51,9 @@ private:
    WMLog(const WMLog&) = delete;
    WMLog& operator=(const WMLog&) = delete;
 
-   void WriteMessage(const TCHAR* msg);
+   void WriteMessage(const wchar_t* msg);
    void DeleteLogFile();
 
    bool enabled_;
-#ifdef UNICODE
    std::wofstream logFile_;
-#else
-   std::ofstream logFile_;
-#endif
 };
index fc0d7da4a7a9dfe624f262c72a42d7fd45a5cc34..74068b1e63e3915951f9159a7ea88c312a1f7bfa 100644 (file)
@@ -33,76 +33,76 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #include "common.h"
 
-static const LPCWSTR LX_SYSTEMS_SUBKEY
-   = _T("SOFTWARE\\lx-systems\\WinMute");
-static const LPCWSTR LX_SYSTEMS_WIFI_SUBKEY
-   = _T("SOFTWARE\\lx-systems\\WinMute\\WifiNetworks");
-static const LPCWSTR LX_SYSTEMS_BLUETOOTH_SUBKEY
-   = _T("SOFTWARE\\lx-systems\\WinMute\\BluetoothDevices");
+static const wchar_t *LX_SYSTEMS_SUBKEY
+   = L"SOFTWARE\\lx-systems\\WinMute";
+static const wchar_t* LX_SYSTEMS_WIFI_SUBKEY
+   = L"SOFTWARE\\lx-systems\\WinMute\\WifiNetworks";
+static const wchar_t* LX_SYSTEMS_BLUETOOTH_SUBKEY
+   = L"SOFTWARE\\lx-systems\\WinMute\\BluetoothDevices";
 
-static const LPCWSTR LX_SYSTEMS_AUTOSTART_KEY
-   = _T("LX-Systems WinMute");
+static const wchar_t* LX_SYSTEMS_AUTOSTART_KEY
+   = L"LX-Systems WinMute";
 
-static LPCWSTR KeyToStr(SettingsKey key)
+static const wchar_t* KeyToStr(SettingsKey key)
 {
-   LPCWSTR keyStr = nullptr;
+   const wchar_t* keyStr = nullptr;
    switch (key) {
    case SettingsKey::MUTE_ON_LOCK:
-      keyStr = _T("MuteOnLock");
+      keyStr = L"MuteOnLock";
       break;
    case SettingsKey::MUTE_ON_SCREENSAVER:
-      keyStr = _T("MuteOnScreensaver");
+      keyStr = L"MuteOnScreensaver";
       break;
    case SettingsKey::MUTE_ON_DISPLAYSTANDBY:
-      keyStr = _T("MuteOnDisplayStandby");
+      keyStr = L"MuteOnDisplayStandby";
       break;
    case SettingsKey::MUTE_ON_RDP:
-      keyStr = _T("MuteOnRDP");
+      keyStr = L"MuteOnRDP";
       break;
    case SettingsKey::RESTORE_AUDIO:
-      keyStr = _T("RestoreAudio");
+      keyStr = L"RestoreAudio";
       break;
    case SettingsKey::MUTE_ON_SUSPEND:
-      keyStr = _T("MuteOnSuspend");
+      keyStr = L"MuteOnSuspend";
       break;
    case SettingsKey::MUTE_ON_SHUTDOWN:
-      keyStr = _T("MuteOnShutdown");
+      keyStr = L"MuteOnShutdown";
       break;
    case SettingsKey::MUTE_ON_LOGOUT:
-      keyStr = _T("MuteOnLogout");
+      keyStr = L"MuteOnLogout";
       break;
    case SettingsKey::MUTE_ON_BLUETOOTH:
-      keyStr = _T("MuteOnBluetooth");
+      keyStr = L"MuteOnBluetooth";
       break;
    case SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST:
-      keyStr = _T("MuteOnBluetoothDeviceList");
+      keyStr = L"MuteOnBluetoothDeviceList";
       break;
    case SettingsKey::MUTE_ON_WLAN:
-      keyStr = _T("MuteOnWlan");
+      keyStr = L"MuteOnWlan";
       break;
    case SettingsKey::MUTE_ON_WLAN_ALLOWLIST:
-      keyStr = _T("MuteOnWlanAllowList");
+      keyStr = L"MuteOnWlanAllowList";
       break;
    case SettingsKey::QUIETHOURS_ENABLE:
-      keyStr = _T("QuietHoursEnabled");
+      keyStr = L"QuietHoursEnabled";
       break;
    case SettingsKey::QUIETHOURS_FORCEUNMUTE:
-      keyStr = _T("QuietHoursForceUnmute");
+      keyStr = L"QuietHoursForceUnmute";
       break;
    case SettingsKey::QUIETHOURS_NOTIFICATIONS:
-      keyStr = _T("QuietHoursNotifications");
+      keyStr = L"QuietHoursNotifications";
       break;
    case SettingsKey::QUIETHOURS_START:
-      keyStr = _T("QuietHoursStart");
+      keyStr = L"QuietHoursStart";
       break;
    case SettingsKey::QUIETHOURS_END:
-      keyStr = _T("QuietHoursEnd");
+      keyStr = L"QuietHoursEnd";
       break;
    case SettingsKey::LOGGING_ENABLED:
-      keyStr = _T("Logging");
+      keyStr = L"Logging";
       break;
    case SettingsKey::NOTIFICATIONS_ENABLED:
-      keyStr = _T("ShowNotifications");
+      keyStr = L"ShowNotifications";
       break;
    }
    return keyStr;
@@ -160,23 +160,23 @@ static void NormalizeStringList(std::vector<std::basic_string<T>> &items)
    }
 }
 
-static bool ReadStringFromRegistry(HKEY hKey, const TCHAR* subKey, tstring& val)
+static bool ReadStringFromRegistry(HKEY hKey, const wchar_t *subKey, std::wstring& val)
 {
    bool success = false;
    DWORD regError = 0;
    DWORD bufSize = 0;
-   regError = RegQueryValueEx(hKey, subKey, nullptr, nullptr, nullptr, &bufSize);
+   regError = RegQueryValueExW(hKey, subKey, nullptr, nullptr, nullptr, &bufSize);
    if (regError != ERROR_SUCCESS) {
       if (regError != ERROR_FILE_NOT_FOUND) {
-         PrintWindowsError(_T("RegQueryValueEx"), regError);
+         PrintWindowsError(L"RegQueryValueEx", regError);
       }
    } else {
       bufSize += 1; // Trailing '\0'
-      TCHAR *buf = new TCHAR[bufSize];
-      regError = RegQueryValueEx(hKey, subKey, nullptr, nullptr,
+      wchar_t *buf = new wchar_t[bufSize];
+      regError = RegQueryValueExW(hKey, subKey, nullptr, nullptr,
                                  reinterpret_cast<LPBYTE>(buf), &bufSize);
       if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegQueryValueEx"), regError);
+         PrintWindowsError(L"RegQueryValueEx", regError);
       } else {
          success = true;
          val = buf;
@@ -202,7 +202,7 @@ WMSettings::~WMSettings()
 bool WMSettings::Init()
 {
    if (hSettingsKey_ == nullptr) {
-      DWORD regError = RegCreateKeyEx(
+      DWORD regError = RegCreateKeyExW(
          HKEY_CURRENT_USER,
          LX_SYSTEMS_SUBKEY,
          0,
@@ -213,12 +213,12 @@ bool WMSettings::Init()
          &hSettingsKey_,
          nullptr);
       if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegCreateKeyEx"), regError);
+         PrintWindowsError(L"RegCreateKeyEx", regError);
          return false;
       }
    }
    if (hWifiKey_ == nullptr) {
-      DWORD regError = RegCreateKeyEx(
+      DWORD regError = RegCreateKeyExW(
          HKEY_CURRENT_USER,
          LX_SYSTEMS_WIFI_SUBKEY,
          0,
@@ -229,14 +229,14 @@ bool WMSettings::Init()
          &hWifiKey_,
          nullptr);
       if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegCreateKeyEx"), regError);
+         PrintWindowsError(L"RegCreateKeyEx", regError);
          RegCloseKey(hSettingsKey_);
          hSettingsKey_ = nullptr;
          return false;
       }
    }
    if (hBluetoothKey_ == nullptr) {
-      DWORD regError = RegCreateKeyEx(
+      DWORD regError = RegCreateKeyExW(
          HKEY_CURRENT_USER,
          LX_SYSTEMS_BLUETOOTH_SUBKEY,
          0,
@@ -247,7 +247,7 @@ bool WMSettings::Init()
          &hBluetoothKey_,
          nullptr);
       if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegCreateKeyEx"), regError);
+         PrintWindowsError(L"RegCreateKeyEx", regError);
          RegCloseKey(hWifiKey_);
          RegCloseKey(hSettingsKey_);
          hSettingsKey_ = nullptr;
@@ -272,14 +272,14 @@ void WMSettings::Unload()
 HKEY WMSettings::OpenAutostartKey(REGSAM samDesired)
 {
    HKEY hRunKey = NULL;
-   DWORD regError = RegOpenKeyEx(
+   DWORD regError = RegOpenKeyExW(
       HKEY_CURRENT_USER,
-      _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
+      L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
       0,
       samDesired,
       &hRunKey);
    if (regError != ERROR_SUCCESS) {
-      PrintWindowsError(_T("RegOpenKeyEx"), regError);
+      PrintWindowsError(L"RegOpenKeyEx", regError);
    }
    return hRunKey;
 }
@@ -288,16 +288,16 @@ bool WMSettings::IsAutostartEnabled()
 {
    bool isEnabled = false;
    WMLog& log = WMLog::GetInstance();
-   TCHAR wmPath[MAX_PATH + 1];
+   wchar_t wmPath[MAX_PATH + 1];
    if (GetModuleFileName(NULL, wmPath, sizeof(wmPath) / sizeof(wmPath[0])) == 0) {
-      log.Write(_T("Failed to get path of winmute"));
+      log.Write(L"Failed to get path of winmute");
    } else {
       HKEY hRunKey = OpenAutostartKey(KEY_READ);
       if (hRunKey != NULL) {
-         tstring path;
+         std::wstring path;
          if (ReadStringFromRegistry(hRunKey, LX_SYSTEMS_AUTOSTART_KEY, path)) {
             if (path != wmPath) {
-               log.Write(_T("Autostart entry has wrong path"));
+               log.Write(L"Autostart entry has wrong path");
             } else {
                isEnabled = true;
             }
@@ -314,25 +314,25 @@ void WMSettings::EnableAutostart(bool enable)
    HKEY hRunKey = OpenAutostartKey(KEY_WRITE);
    if (hRunKey != NULL) {
       if (enable) {
-         TCHAR wmPath[MAX_PATH + 1];
-         if (GetModuleFileName(NULL, wmPath, sizeof(wmPath) / sizeof(wmPath[0])) == 0) {
-            log.Write(_T("Failed to get path of winmute"));
+         wchar_t wmPath[MAX_PATH + 1];
+         if (GetModuleFileNameW(NULL, wmPath, sizeof(wmPath) / sizeof(wmPath[0])) == 0) {
+            log.Write(L"Failed to get path of winmute");
          } else {
-            DWORD regError = RegSetKeyValue(
+            DWORD regError = RegSetKeyValueW(
                hRunKey,
                NULL,
                LX_SYSTEMS_AUTOSTART_KEY,
                REG_SZ,
                wmPath,
-               (lstrlen(wmPath) + 1) * sizeof(TCHAR));
+               (lstrlen(wmPath) + 1) * sizeof(wchar_t));
             if (regError != ERROR_SUCCESS) {
-               PrintWindowsError(_T("RegSetKeyValue"), regError);
+               PrintWindowsError(L"RegSetKeyValue", regError);
             }
          }
       } else {
-         DWORD regError = RegDeleteKeyValue(hRunKey, NULL, LX_SYSTEMS_AUTOSTART_KEY);
+         DWORD regError = RegDeleteKeyValueW(hRunKey, NULL, LX_SYSTEMS_AUTOSTART_KEY);
          if (regError != ERROR_SUCCESS && regError != ERROR_FILE_NOT_FOUND) {
-            PrintWindowsError(_T("RegDeleteKeyValue"), regError);
+            PrintWindowsError(L"RegDeleteKeyValue", regError);
          }
       }
       RegCloseKey(hRunKey);
@@ -346,7 +346,7 @@ DWORD WMSettings::QueryValue(SettingsKey key) const
 
    DWORD value = 0;
    DWORD size = sizeof(DWORD);
-   DWORD regError = RegQueryValueEx(
+   DWORD regError = RegQueryValueExW(
       hSettingsKey_,
       keyStr,
       0,
@@ -355,7 +355,7 @@ DWORD WMSettings::QueryValue(SettingsKey key) const
       &size);
    if (regError != ERROR_SUCCESS) {
       if (regError != ERROR_FILE_NOT_FOUND) {
-         PrintWindowsError(_T("RegCreateKeyEx"), regError);
+         PrintWindowsError(L"RegCreateKeyEx", regError);
       }
       return GetDefaultSetting(key);
    }
@@ -368,7 +368,7 @@ bool WMSettings::SetValue(SettingsKey key, DWORD value)
    auto keyStr = KeyToStr(key);
    assert(keyStr != nullptr);
 
-   DWORD regError = RegSetValueEx(
+   DWORD regError = RegSetValueExW(
       hSettingsKey_,
       keyStr,
       0,
@@ -376,20 +376,20 @@ bool WMSettings::SetValue(SettingsKey key, DWORD value)
       reinterpret_cast<BYTE*>(&value),
       sizeof(DWORD));
    if (regError != ERROR_SUCCESS) {
-      PrintWindowsError(_T("RegCreateKeyEx"), regError);
+      PrintWindowsError(L"RegCreateKeyEx", regError);
       return false;
    }
 
    return true;
 }
 
-bool WMSettings::StoreWifiNetworks(std::vector<tstring>& networks)
+bool WMSettings::StoreWifiNetworks(std::vector<std::wstring>& networks)
 {
    // Clear all stored keys
    for (;;) {
-      TCHAR valueName[260] = { 0 };
+      wchar_t valueName[260] = { 0 };
       DWORD valueSize = ARRAY_SIZE(valueName);
-      DWORD regError = RegEnumValue(
+      DWORD regError = RegEnumValueW(
          hWifiKey_,
          0,
          valueName,
@@ -401,12 +401,12 @@ bool WMSettings::StoreWifiNetworks(std::vector<tstring>& networks)
       if (regError == ERROR_NO_MORE_ITEMS) {
          break;
       } else if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegEnumValue"), regError);
+         PrintWindowsError(L"RegEnumValue", regError);
          return false;
       } else {
          regError = RegDeleteValue(hWifiKey_, valueName);
          if (regError != ERROR_SUCCESS) {
-            PrintWindowsError(_T("RegDeleteValue"), regError);
+            PrintWindowsError(L"RegDeleteValue", regError);
             return false;
          }
       }
@@ -415,18 +415,18 @@ bool WMSettings::StoreWifiNetworks(std::vector<tstring>& networks)
    NormalizeStringList(networks);
 
    for (size_t i = 0; i < networks.size(); ++i) {
-      TCHAR valueName[25];
-      StringCchPrintfW(valueName, ARRAY_SIZE(valueName), _T("WiFi %03d"), i + 1);
-      const tstring& v = networks[i];
-      DWORD regError = RegSetValueEx(
+      wchar_t valueName[25];
+      StringCchPrintfW(valueName, ARRAY_SIZE(valueName), L"WiFi %03ld", i + 1);
+      const std::wstring& v = networks[i];
+      DWORD regError = RegSetValueExW(
          hWifiKey_,
          valueName,
          NULL,
          REG_SZ,
          reinterpret_cast<const BYTE*>(v.c_str()),
-         static_cast<DWORD>(v.length() + 1) * sizeof(TCHAR));
+         static_cast<DWORD>(v.length() + 1) * sizeof(wchar_t));
       if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegSetValueEx"), regError);
+         PrintWindowsError(L"RegSetValueEx", regError);
          return false;
       }
    }
@@ -434,17 +434,17 @@ bool WMSettings::StoreWifiNetworks(std::vector<tstring>& networks)
    return true;
 }
 
-std::vector<tstring> WMSettings::GetWifiNetworks() const
+std::vector<std::wstring> WMSettings::GetWifiNetworks() const
 {
-   std::vector<tstring> networks;
+   std::vector<std::wstring> networks;
    for (int valIdx = 0; ; ++valIdx) {
-      TCHAR valueName[260] = { 0 };
-      TCHAR dataBuf[260] = { 0 };
+      wchar_t valueName[260] = { 0 };
+      wchar_t dataBuf[260] = { 0 };
       DWORD valueSize = ARRAY_SIZE(valueName);
       DWORD valType = 0;
       DWORD dataLen = ARRAY_SIZE(dataBuf);
 
-      DWORD regError = RegEnumValue(
+      DWORD regError = RegEnumValueW(
          hWifiKey_,
          valIdx,
          valueName,
@@ -456,7 +456,7 @@ std::vector<tstring> WMSettings::GetWifiNetworks() const
       if (regError == ERROR_NO_MORE_ITEMS) {
          break;
       } else if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegEnumValue"), regError);
+         PrintWindowsError(L"RegEnumValue", regError);
          return {};
       } else {
          networks.push_back(dataBuf);
@@ -466,13 +466,13 @@ std::vector<tstring> WMSettings::GetWifiNetworks() const
    return networks;
 }
 
-bool WMSettings::StoreBluetoothDevices(std::vector<tstring>& devices)
+bool WMSettings::StoreBluetoothDevices(std::vector<std::wstring>& devices)
 {
    // Clear all stored keys
    for (;;) {
-      TCHAR valueName[260] = { 0 };
+      wchar_t valueName[260] = { 0 };
       DWORD valueSize = ARRAY_SIZE(valueName);
-      DWORD regError = RegEnumValue(
+      DWORD regError = RegEnumValueW(
          hBluetoothKey_,
          0,
          valueName,
@@ -484,12 +484,12 @@ bool WMSettings::StoreBluetoothDevices(std::vector<tstring>& devices)
       if (regError == ERROR_NO_MORE_ITEMS) {
          break;
       } else if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegEnumValue"), regError);
+         PrintWindowsError(L"RegEnumValue", regError);
          return false;
       } else {
          regError = RegDeleteValue(hBluetoothKey_, valueName);
          if (regError != ERROR_SUCCESS) {
-            PrintWindowsError(_T("RegDeleteValue"), regError);
+            PrintWindowsError(L"RegDeleteValue", regError);
             return false;
          }
       }
@@ -498,21 +498,21 @@ bool WMSettings::StoreBluetoothDevices(std::vector<tstring>& devices)
    NormalizeStringList(devices);
 
    for (size_t i = 0; i < devices.size(); ++i) {
-      TCHAR valueName[25];
+      wchar_t valueName[25];
       StringCchPrintfW(
          valueName,
          ARRAY_SIZE(valueName),
-         _T("Bluetooth %03d"), i + 1);
-      const tstring& v = devices[i];
+         L"Bluetooth %03ld", i + 1);
+      const std::wstring& v = devices[i];
       DWORD regError = RegSetValueEx(
          hBluetoothKey_,
          valueName,
          NULL,
          REG_SZ,
          reinterpret_cast<const BYTE*>(v.c_str()),
-         static_cast<DWORD>(v.length() + 1) * sizeof(TCHAR));
+         static_cast<DWORD>(v.length() + 1) * sizeof(wchar_t));
       if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegSetValueEx"), regError);
+         PrintWindowsError(L"RegSetValueEx", regError);
          return false;
       }
    }
@@ -542,7 +542,7 @@ std::vector<std::string> WMSettings::GetBluetoothDevicesA() const
       if (regError == ERROR_NO_MORE_ITEMS) {
          break;
       } else if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegEnumValue"), regError);
+         PrintWindowsError(L"RegEnumValue", regError);
          return {};
       } else {
          devices.push_back(dataBuf);
@@ -574,7 +574,7 @@ std::vector<std::wstring> WMSettings::GetBluetoothDevicesW() const
       if (regError == ERROR_NO_MORE_ITEMS) {
          break;
       } else if (regError != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegEnumValue"), regError);
+         PrintWindowsError(L"RegEnumValue", regError);
          return {};
       } else {
          devices.push_back(dataBuf);
index 807f05eeac17e4a7dddc208fdb06cb355d136bae..34f5781b5640e407c8503fe7dc222d7a3bca5ae0 100644 (file)
@@ -71,10 +71,10 @@ public:
    bool IsAutostartEnabled();
    void EnableAutostart(bool enable);
 
-   bool StoreWifiNetworks(std::vector<tstring>& networks);
-   std::vector<tstring> GetWifiNetworks() const;
+   bool StoreWifiNetworks(std::vector<std::wstring>& networks);
+   std::vector<std::wstring> GetWifiNetworks() const;
 
-   bool StoreBluetoothDevices(std::vector<tstring>& networks);
+   bool StoreBluetoothDevices(std::vector<std::wstring>& networks);
    std::vector<std::wstring> GetBluetoothDevicesW() const;
    std::vector<std::string> GetBluetoothDevicesA() const;
 
index 4435fe6f6ffa30dfa78349e2bbadebb1b8ae8063..6d94c7627e6d1323bc238e6c657f260f181f0d2b 100644 (file)
@@ -47,7 +47,7 @@ public:
 
    bool Init(HWND hNotifyWnd);
    void Unload();
-   void SetNetworkList(const std::vector<tstring> networks, bool isMuteList);
+   void SetNetworkList(const std::vector<std::wstring> networks, bool isMuteList);
 
    void CheckNetwork();
    void WlanNotificationCallback(PWLAN_NOTIFICATION_DATA notifyData);
@@ -60,5 +60,5 @@ private:
    // not be muted.
    bool isMuteList_;
    bool initialized_;
-   std::vector<tstring> networks_;
+   std::vector<std::wstring> networks_;
 };
index 90ac5aa8239096c2d5315e11bdc3dac2229ea4f9..416039ed2a4661b1313970d7c18346579d3160d5 100644 (file)
@@ -72,14 +72,14 @@ bool WifiDetector::Init(HWND hNotifyWnd)
       DWORD wlErr = WlanOpenHandle(vers, NULL, &vers, &wlanHandle_);
       if (wlErr != ERROR_SUCCESS) {
          if (wlErr != ERROR_SERVICE_NOT_ACTIVE) {
-            PrintWindowsError(_T("WlanOpenHandle"), wlErr);
+            PrintWindowsError(L"WlanOpenHandle", wlErr);
          }
       } else {
          wlErr = WlanRegisterNotification(
             wlanHandle_, WLAN_NOTIFICATION_SOURCE_ACM, TRUE,
             ::WlanNotificationCallback, this, NULL, NULL);
          if (wlErr != ERROR_SUCCESS) {
-            PrintWindowsError(_T("WlanOpenHandle"), wlErr);
+            PrintWindowsError(L"WlanOpenHandle", wlErr);
             WlanCloseHandle(wlanHandle_, NULL);
          } else {
             initialized_ = true;
@@ -89,7 +89,7 @@ bool WifiDetector::Init(HWND hNotifyWnd)
    return initialized_;
 }
 
-void WifiDetector::SetNetworkList(const std::vector<tstring> networks, bool isMuteList)
+void WifiDetector::SetNetworkList(const std::vector<std::wstring> networks, bool isMuteList)
 {
    networks_ = networks;
    isMuteList_ = isMuteList;
@@ -100,7 +100,7 @@ void WifiDetector::CheckNetwork()
    PWLAN_INTERFACE_INFO_LIST ifList;
    DWORD wlanErr = WlanEnumInterfaces(wlanHandle_, NULL, &ifList);
    if (wlanErr != ERROR_SUCCESS) {
-      PrintWindowsError(_T("WlanEnumInterfaces"), wlanErr);
+      PrintWindowsError(L"WlanEnumInterfaces", wlanErr);
    } else {
       for (; ifList->dwIndex < ifList->dwNumberOfItems; ++ifList->dwIndex) {
          PWLAN_AVAILABLE_NETWORK_LIST availList;
@@ -111,7 +111,7 @@ void WifiDetector::CheckNetwork()
             NULL,
             &availList);
          if (wlanErr != ERROR_SUCCESS) {
-            PrintWindowsError(_T("WlanGetAvailableNetworkList"), wlanErr);
+            PrintWindowsError(L"WlanGetAvailableNetworkList", wlanErr);
          } else {
             for (; availList->dwIndex < availList->dwNumberOfItems; ++availList->dwIndex) {
                PWLAN_AVAILABLE_NETWORK net = &availList->Network[availList->dwIndex];
index 73147b060cd143e66220daef2f34f74fd76e5ca9..8a827a5864e8254567ca97461ca013381227377d 100644 (file)
@@ -54,7 +54,7 @@ public:
 };
 
 struct Endpoint {
-   TCHAR deviceName[100];
+   wchar_t deviceName[100];
    IAudioEndpointVolumePtr endpointVolume;
    IAudioSessionControlPtr sessionCtrl;
    std::unique_ptr<VistaAudioSessionEvents> wasapiAudioEvents;
index d2603e26fa371962cac7effae702f516d4ba2e78..c930e60858a705fb67cb833c5f2e66f401555522 100644 (file)
@@ -54,7 +54,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance,
    _In_ PWSTR,
    _In_ int)
 {
-   HANDLE hMutex = CreateMutex(nullptr, TRUE, _T("LxSystemsWinMute"));
+   HANDLE hMutex = CreateMutexW(nullptr, TRUE, L"LxSystemsWinMute");
    if (hMutex == nullptr) {
       return FALSE;
    }
@@ -63,9 +63,9 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance,
       TaskDialog(nullptr,
          nullptr,
          PROGRAM_NAME,
-         _T("WinMute is already running"),
-         _T("Please look for a white speaker icon in your Windows ")
-         _T(" taskbar notification area."),
+         L"WinMute is already running",
+         L"Please look for a white speaker icon in your Windows "
+         L" taskbar notification area.",
          TDCBF_OK_BUTTON,
          TD_INFORMATION_ICON,
          nullptr);
@@ -86,8 +86,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance,
       TaskDialog(nullptr,
          nullptr,
          PROGRAM_NAME,
-         _T("Failed to register extended window controls."),
-         _T("Please try to restart the program."),
+         L"Failed to register extended window controls.",
+         L"Please try to restart the program.",
          TDCBF_OK_BUTTON,
          TD_ERROR_ICON,
          nullptr);
@@ -101,8 +101,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance,
       TaskDialog(nullptr,
          nullptr,
          PROGRAM_NAME,
-         _T("Failed to initialize COM library."),
-         _T("Please try to restart the program."),
+         L"Failed to initialize COM library.",
+         L"Please try to restart the program.",
          TDCBF_OK_BUTTON,
          TD_ERROR_ICON,
          nullptr);
index ec8f7a6fa5583057147aab77ad1434191809f6d8..068bd1d9e1d831bad933316748e26e19592aa7d9 100644 (file)
@@ -39,12 +39,12 @@ extern HINSTANCE hglobInstance;
 extern INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
 extern INT_PTR CALLBACK SettingsDlgProc(HWND, UINT, WPARAM, LPARAM);
 
-static LPCTSTR WINMUTE_CLASS_NAME = _T("WinMute");
+static const wchar_t *WINMUTE_CLASS_NAME = L"WinMute";
 
-static LPCTSTR TERMINAL_SERVER_KEY
-   = _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\");
-static LPCTSTR GLASS_SESSION_ID
-   = _T("GlassSessionId");
+static const wchar_t *TERMINAL_SERVER_KEY
+   = L"SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\";
+static const wchar_t* GLASS_SESSION_ID
+   = L"GlassSessionId";
 
 static LRESULT CALLBACK WinMuteWndProc(
    HWND hWnd,
@@ -72,26 +72,26 @@ static int IsDarkMode(bool& isDarkMode)
    HKEY hKey;
    int rc = 1;
    //RegOpenCurrentUser
-   LSTATUS error = RegOpenKey(
+   LSTATUS error = RegOpenKeyW(
       HKEY_CURRENT_USER,
-      _T("Software\\Microsoft\\Windows\\CurrentVersion\\")
-      _T("Themes\\Personalize"),
+      L"Software\\Microsoft\\Windows\\CurrentVersion\\"
+      L"Themes\\Personalize",
       &hKey);
    if (error != ERROR_SUCCESS) {
-      PrintWindowsError(_T("RegOpenKey"), error);
+      PrintWindowsError(L"RegOpenKey", error);
    } else {
       DWORD isLightTheme = 0;
       DWORD bufSize = sizeof(isLightTheme);
       DWORD valType = 0;
-      error = RegQueryValueEx(
+      error = RegQueryValueExW(
          hKey,
-         _T("SystemUsesLightTheme"),
+         L"SystemUsesLightTheme",
          NULL,
          &valType,
          reinterpret_cast<LPBYTE>(&isLightTheme),
          &bufSize);
       if (error != ERROR_SUCCESS) {
-         PrintWindowsError(_T("RegQueryValueEx"), error);
+         PrintWindowsError(L"RegQueryValueEx", error);
       } else {
          isDarkMode = !isLightTheme;
          rc = 0;
@@ -162,7 +162,7 @@ bool WinMute::RegisterWindowClass()
    wc.lpszClassName = WINMUTE_CLASS_NAME;
 
    if (!RegisterClass(&wc)) {
-      PrintWindowsError(_T("RegisterClass"));
+      PrintWindowsError(L"RegisterClass");
       return false;
    }
    return true;
@@ -173,7 +173,7 @@ bool WinMute::InitWindow()
    hWnd_ = CreateWindowEx(WS_EX_TOOLWINDOW, WINMUTE_CLASS_NAME, PROGRAM_NAME,
       WS_POPUP, 0, 0, 0, 0, NULL, 0, hglobInstance, this);
    if (hWnd_ == nullptr) {
-      PrintWindowsError(_T("CreateWindowEx"));
+      PrintWindowsError(L"CreateWindowEx");
       return false;
    }
    return true;
@@ -184,10 +184,11 @@ bool WinMute::InitAudio()
    if (IsWindowsVistaOrGreater()) {
       // Nothing to do
    } else if (IsWindowsXPOrGreater()) {
-      TaskDialog(nullptr, nullptr, PROGRAM_NAME,
-         _T("Only Windows Vista and newer is supported"),
-         _T("For Windows XP support, please download WinMute ")
-         _T(" version 1.4.2 or older"),
+      TaskDialog(
+         nullptr, nullptr, PROGRAM_NAME,
+         L"Only Windows Vista and newer is supported",
+         L"For Windows XP support, please download WinMute "
+         L" version 1.4.2 or older",
          TDCBF_OK_BUTTON, TD_ERROR_ICON, nullptr);
       return false;
    }
@@ -207,7 +208,7 @@ bool WinMute::InitTrayMenu()
    if (hTrayMenu_ == NULL) {
       hTrayMenu_ = LoadMenu(hglobInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
       if (hTrayMenu_ == NULL) {
-         PrintWindowsError(_T("LoadMenu"));
+         PrintWindowsError(L"LoadMenu");
          return false;
       }
    }
@@ -239,7 +240,7 @@ bool WinMute::Init()
 #else
    WMLog::GetInstance().SetEnabled(settings_.QueryValue(SettingsKey::LOGGING_ENABLED));
 #endif
-   log.Write(_T("Starting new session..."));
+   log.Write(L"Starting new session...");
 
    if (!RegisterWindowClass() || !InitWindow()) {
       return false;
@@ -268,12 +269,12 @@ bool WinMute::Init()
    }
 
    if (!WTSRegisterSessionNotification(hWnd_, NOTIFY_FOR_THIS_SESSION)) {
-      PrintWindowsError(_T("WTSRegisterSessionNotification"));
+      PrintWindowsError(L"WTSRegisterSessionNotification");
       return false;
    }
 
    if (!RegisterPowerSettingNotification(hWnd_, &GUID_CONSOLE_DISPLAY_STATE, 0)) {
-      PrintWindowsError(_T("RegisterPowerSettingNotification"));
+      PrintWindowsError(L"RegisterPowerSettingNotification");
       return false;
    }
 
@@ -287,18 +288,18 @@ bool WinMute::Init()
       PrintWindowsError(_T("LoadIcon"));
       return false;
    }
-   trayIcon_.Init(hWnd_, 0, hTrayIcon_, _T("WinMute"), true);
+   trayIcon_.Init(hWnd_, 0, hTrayIcon_, L"WinMute", true);
 
 
    quietHours_.Init(hWnd_, settings_);
 
-   log.Write(_T("WinMute initialized"));
+   log.Write(L"WinMute initialized");
 
    if (settings_.QueryValue(SettingsKey::MUTE_ON_RDP)
        && IsCurrentSessionRemoteable()) {
       trayIcon_.ShowPopup(
-         _T("Remote Session detected"),
-         _T("All audio endpoints have been muted"));
+         L"Remote Session detected",
+         L"All audio endpoints have been muted");
       muteCtrl_.SetMute(true);
    }
 
@@ -325,9 +326,9 @@ bool WinMute::LoadSettings()
    } else {
       if (!btDetector_.Init(hWnd_)) {
          trayIcon_.ShowPopup(
-            _T("Bluetooth muting disabled"),
-            _T("Bluetooth is not available or disabled. ")
-            _T("Bluetooth muting will be disabled on this computer"));
+            L"Bluetooth muting disabled",
+            L"Bluetooth is not available or disabled. "
+            L"Bluetooth muting will be disabled on this computer");
          settings_.SetValue(SettingsKey::MUTE_ON_BLUETOOTH, FALSE);
       } else {
          bool muteOnWithDeviceList = settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST);
@@ -341,9 +342,9 @@ bool WinMute::LoadSettings()
    } else {
       if (!wifiDetector_.Init(hWnd_)) {
          trayIcon_.ShowPopup(
-            _T("WLAN muting disabled"),
-            _T("WLAN is not available or disabled. ")
-            _T("WLAN muting will be disabled on this computer"));
+            L"WLAN muting disabled",
+            L"WLAN is not available or disabled. "
+            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);
@@ -376,7 +377,7 @@ LRESULT CALLBACK WinMute::WindowProc(
    static UINT uTaskbarRestart = 0;
    switch (msg) {
    case WM_CREATE: {
-      uTaskbarRestart = RegisterWindowMessage(_T("TaskbarCreated"));
+      uTaskbarRestart = RegisterWindowMessageW(L"TaskbarCreated");
       return TRUE;
    }
    case WM_COMMAND: {
@@ -495,8 +496,10 @@ LRESULT CALLBACK WinMute::WindowProc(
          POINT p = { 0 };
          GetCursorPos(&p);
          SetForegroundWindow(hWnd);
-         TrackPopupMenuEx(GetSubMenu(hTrayMenu_, 0), TPM_NONOTIFY | TPM_TOPALIGN
-            | TPM_LEFTALIGN, p.x, p.y, hWnd_, nullptr);
+         TrackPopupMenuEx(
+            GetSubMenu(hTrayMenu_, 0),
+            TPM_NONOTIFY | TPM_TOPALIGN | TPM_LEFTALIGN,
+            p.x, p.y, hWnd_, nullptr);
          break;
       }
       default:
@@ -544,8 +547,8 @@ LRESULT CALLBACK WinMute::WindowProc(
       muteCtrl_.NotifyQuietHours(true);
       if (settings_.QueryValue(SettingsKey::QUIETHOURS_NOTIFICATIONS)) {
          trayIcon_.ShowPopup(
-            _T("WinMute: Quiet hours started"),
-            _T("Your workstation audio will now be muted."));
+            L"WinMute: Quiet hours started",
+            L"Your workstation audio will now be muted.");
       }
       quietHours_.SetEnd();
       return 0;
@@ -553,8 +556,8 @@ LRESULT CALLBACK WinMute::WindowProc(
       muteCtrl_.NotifyQuietHours(false);
       if (settings_.QueryValue(SettingsKey::QUIETHOURS_NOTIFICATIONS)) {
          trayIcon_.ShowPopup(
-            _T("WinMute: Quiet Hours ended"),
-            _T("Your workstation audio has been restored."));
+            L"WinMute: Quiet Hours ended",
+            L"Your workstation audio has been restored.");
       }
       if (settings_.QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE)) {
          muteCtrl_.SetMute(false);
@@ -575,15 +578,15 @@ LRESULT CALLBACK WinMute::WindowProc(
          if (btStatus == BluetoothDetector::BluetoothStatus::Connected) {
             if (settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED)) {
                trayIcon_.ShowPopup(
-                  _T("Bluetooth muting"),
-                  _T("Bluetooth device connected: Restoring audio"));
+                  L"Bluetooth muting",
+                  L"Bluetooth device connected: Restoring audio");
             }
             muteCtrl_.SetMute(false);
          } else if (btStatus == BluetoothDetector::BluetoothStatus::Disconnected) {
             if (settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED)) {
                trayIcon_.ShowPopup(
-                  _T("Bluetooth muting"),
-                  _T("Bluetooth device disconnected: Muting"));
+                  L"Bluetooth muting",
+                  L"Bluetooth device disconnected: Muting");
             }
             muteCtrl_.SetMute(true);
          }
@@ -594,20 +597,20 @@ LRESULT CALLBACK WinMute::WindowProc(
       if (muteConfig_.muteOnWlan) {
          if (wParam == 1) { // Connected
             if (settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED)) {
-               TCHAR msgBuf[260] = { 0 };
-               TCHAR* wifiName = reinterpret_cast<TCHAR*>(lParam);
+               wchar_t msgBuf[260] = { 0 };
+               wchar_t* wifiName = reinterpret_cast<wchar_t*>(lParam);
                if (settings_.QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST)) {
                   StringCchPrintfW(
                      msgBuf, ARRAY_SIZE(msgBuf),
-                     _T("WLAN \"%s\"network is not on allowed list.\n"),
+                     L"WLAN \"%s\"network is not on allowed list.\n",
                      wifiName);
                }  else {
                   StringCchPrintfW(
                      msgBuf, ARRAY_SIZE(msgBuf),
-                     _T("WLAN network \"%s\" is configured for AutoMute."),
+                     L"WLAN network \"%s\" is configured for AutoMute.",
                      wifiName);
                }
-               trayIcon_.ShowPopup(_T("Workstation muted"), msgBuf);
+               trayIcon_.ShowPopup(L"Workstation muted", msgBuf);
                delete [] wifiName;
             }
             muteCtrl_.SetMute(true);
@@ -615,15 +618,15 @@ LRESULT CALLBACK WinMute::WindowProc(
       }
       return 0;
    case WM_SETTINGCHANGE: {
-      if (lstrcmp(LPCTSTR(lParam), _T("ImmersiveColorSet")) == 0) {
+      if (wcscmp(reinterpret_cast<const wchar_t*>(lParam), L"ImmersiveColorSet") == 0) {
          bool isDarkMode = true;
          IsDarkMode(isDarkMode);
-         hTrayIcon_ = LoadIcon(
+         hTrayIcon_ = LoadIconW(
             hglobInstance,
             isDarkMode ? MAKEINTRESOURCE(IDI_TRAY_DARK)
             : MAKEINTRESOURCE(IDI_TRAY_BRIGHT));
          if (hTrayIcon_ == NULL) {
-            PrintWindowsError(_T("LoadIcon"));
+            PrintWindowsError(L"LoadIcon");
          } else {
             trayIcon_.ChangeIcon(hTrayIcon_);
          }
index 26f06367419c8615960ca6bc87a98601a5f08a46..3c81307372f61bcae4e62c29fa094ac1f038f08b 100644 (file)
       <SDLCheck>true</SDLCheck>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <ConformanceMode>true</ConformanceMode>
-      <LanguageStandard>stdcpplatest</LanguageStandard>
+      <LanguageStandard>stdcpp20</LanguageStandard>
       <TreatWarningAsError>true</TreatWarningAsError>
       <DiagnosticsFormat>Caret</DiagnosticsFormat>
       <PrecompiledHeader>Use</PrecompiledHeader>
       <SDLCheck>true</SDLCheck>
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <ConformanceMode>true</ConformanceMode>
-      <LanguageStandard>stdcpplatest</LanguageStandard>
+      <LanguageStandard>stdcpp20</LanguageStandard>
       <TreatWarningAsError>true</TreatWarningAsError>
       <DiagnosticsFormat>Caret</DiagnosticsFormat>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
       <SDLCheck>true</SDLCheck>
       <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <ConformanceMode>true</ConformanceMode>
-      <LanguageStandard>stdcpplatest</LanguageStandard>
+      <LanguageStandard>stdcpp20</LanguageStandard>
       <TreatWarningAsError>true</TreatWarningAsError>
       <DiagnosticsFormat>Caret</DiagnosticsFormat>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
     </Manifest>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClInclude Include="BaseTypes.h" />
     <ClInclude Include="BluetoothDetector.h" />
     <ClInclude Include="common.h" />
     <ClInclude Include="WiFiDetector.h" />
index 7c520e697f8afc3da31bbb4cc0eb8b22706a1a43..b68194cc608dce0ce9891f01e501df64c730cf91 100644 (file)
@@ -98,9 +98,6 @@
     <ClInclude Include="MuteControl.h">
       <Filter>Source Files\Controllers\Muting</Filter>
     </ClInclude>
-    <ClInclude Include="BaseTypes.h">
-      <Filter>Source Files</Filter>
-    </ClInclude>
     <ClInclude Include="WiFiDetector.h">
       <Filter>Source Files\Controllers\WiFi</Filter>
     </ClInclude>
index adbe021766e0a034a963ffb5a2f41a6bbff7fc57..44da2b9b1ef299511e391e93af6b75a606dae7f5 100644 (file)
@@ -33,16 +33,22 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #pragma once
 
-#ifdef _UNICODE
+#ifndef UNICODE
+#  define UNICODE
+#endif
+
+#ifndef _UNICODE
+#  define _UNICODE
+#endif
+
 #if defined _M_IX86
-#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#  pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
 #elif defined _M_IA64
-#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#  pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
 #elif defined _M_X64
-#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#  pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
 #else
-#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
-#endif
+#  pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
 #endif
 
 #define STRICT
@@ -53,15 +59,16 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <array>
 #include <cassert>
 #include <chrono>
+#include <cstdarg>
 #include <filesystem>
 #include <fstream>
+#include <iterator>
+#include <locale>
 #include <memory>
 #include <string_view>
 #include <string>
 #include <unordered_map>
 #include <vector>
-#include <cstdarg>
-#include <iterator>
 
 #include <windows.h>
 #include <windowsx.h>
@@ -85,7 +92,6 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #include "resource.h"
 
-#include "BaseTypes.h"
 #include "WMSettings.h"
 #include "ScreensaverNotifier.h"
 #include "WMLog.h"
@@ -99,9 +105,9 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "VersionHelper.h"
 
 // Utility
-void PrintWindowsError(LPCWSTR lpszFunction, DWORD lastError = -1);
+void PrintWindowsError(const wchar_t *functionName, DWORD lastError = -1);
 
-static const LPCTSTR PROGRAM_NAME = _T("WinMute");
+static const wchar_t *PROGRAM_NAME = L"WinMute";
 constexpr int WM_SAVESETTINGS = WM_USER + 300;
 
 template<class Interface>