From: lx-s Date: Thu, 11 Aug 2016 09:06:54 +0000 (+0200) Subject: Upgraded project to Visual Studio 2015. Fixed analyzer warnings. X-Git-Tag: 1.4.3~10 X-Git-Url: https://repos.lx-s.de/gitweb/?a=commitdiff_plain;h=46c032e491fbe5a58745b49f8d3708cc56793091;p=winmute.git Upgraded project to Visual Studio 2015. Fixed analyzer warnings. --- diff --git a/ScreensaverNotify/ScreensaverNotify.vcxproj b/ScreensaverNotify/ScreensaverNotify.vcxproj index 3ece113..6bb6e10 100644 --- a/ScreensaverNotify/ScreensaverNotify.vcxproj +++ b/ScreensaverNotify/ScreensaverNotify.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -15,18 +15,19 @@ Win32Proj ScreensaverNotify ScreensaverNotify + 8.1 DynamicLibrary true - v120 + v140 Unicode DynamicLibrary false - v120_xp + v140 true Unicode @@ -58,6 +59,7 @@ WIN32;_DEBUG;_WINDOWS;_USRDLL;WINMUTEDLL_EXPORTS;%(PreprocessorDefinitions) true true + true Windows @@ -75,6 +77,7 @@ true true MultiThreaded + true Windows diff --git a/WinMute/TrayIcon.cpp b/WinMute/TrayIcon.cpp index ac3594e..156b67a 100644 --- a/WinMute/TrayIcon.cpp +++ b/WinMute/TrayIcon.cpp @@ -14,7 +14,7 @@ modification, are permitted provided that the following conditions are met: 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 + 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" @@ -50,7 +50,7 @@ void TrayIcon::Init(HWND hWnd, UINT trayID, HICON hIcon, const std::wstring& tooltip, bool show) { if (!hIcon) { - hIcon_ = LoadIcon(0, MAKEINTRESOURCE(IDI_APPLICATION)); + hIcon_ = LoadIcon(0, IDI_APPLICATION); } else { hIcon_ = hIcon; } @@ -142,9 +142,13 @@ bool TrayIcon::AddNotifyIcon() tnid.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE; tnid.hIcon = hIcon_; tnid.uCallbackMessage = WM_TRAYICON; - lstrcpyn(tnid.szTip, tooltip_.c_str(), sizeof(tnid.szTip) / sizeof(TCHAR)); - return Shell_NotifyIcon(NIM_ADD, &tnid) != 0; + if (SUCCEEDED(StringCchCopy(tnid.szTip, + sizeof(tnid.szTip) / sizeof(TCHAR), + tooltip_.c_str()))) { + return Shell_NotifyIcon(NIM_ADD, &tnid) != 0; + } + return false; } bool TrayIcon::RemoveNotifyIcon() @@ -166,7 +170,11 @@ bool TrayIcon::ChangeText() tnid.hWnd = hWnd_; tnid.uID = trayID_; tnid.uFlags = NIF_TIP; - lstrcpyn(tnid.szTip, tooltip_.c_str(), sizeof(tnid.szTip) / sizeof(TCHAR)); - return Shell_NotifyIcon(NIM_MODIFY, &tnid) != 0; + if (SUCCEEDED(StringCchCopy(tnid.szTip, + sizeof(tnid.szTip) / sizeof(TCHAR), + tooltip_.c_str()))) { + return Shell_NotifyIcon(NIM_MODIFY, &tnid) != 0; + } + return false; } diff --git a/WinMute/Utility.cpp b/WinMute/Utility.cpp index 79543c1..197f5ea 100644 --- a/WinMute/Utility.cpp +++ b/WinMute/Utility.cpp @@ -14,7 +14,7 @@ modification, are permitted provided that the following conditions are met: 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 + 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" @@ -33,16 +33,16 @@ POSSIBILITY OF SUCH DAMAGE. #include "StdAfx.h" -void PrintWindowsError(LPTSTR lpszFunction, DWORD lastError) -{ +void PrintWindowsError(LPTSTR lpszFunction, DWORD lastError) +{ // Retrieve the system error message for the last-error code if (lastError == -1) { - lastError = GetLastError(); + lastError = GetLastError(); } LPVOID lpMsgBuf; if (FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), @@ -54,13 +54,15 @@ void PrintWindowsError(LPTSTR lpszFunction, DWORD lastError) lstrlen(static_cast(lpszFunction)) + 40) * sizeof(TCHAR))); if (lpDisplayBuf) { - StringCchPrintf((LPTSTR)lpDisplayBuf, - LocalSize(lpDisplayBuf), - _T("%s failed with error %d: %s"), - lpszFunction, lastError, lpMsgBuf); + StringCchPrintf((LPTSTR)lpDisplayBuf, + LocalSize(lpDisplayBuf), + _T("%s failed with error %ul: %s"), + lpszFunction, + lastError, + reinterpret_cast(lpMsgBuf)); MessageBox(nullptr, static_cast(lpDisplayBuf), _T("Error"), - MB_ICONERROR | MB_OK); + MB_ICONERROR | MB_OK); LocalFree(lpDisplayBuf); } diff --git a/WinMute/VistaAudio.cpp b/WinMute/VistaAudio.cpp index a17f90d..4cf6c4a 100644 --- a/WinMute/VistaAudio.cpp +++ b/WinMute/VistaAudio.cpp @@ -14,7 +14,7 @@ modification, are permitted provided that the following conditions are met: 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 + 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" @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #pragma warning(disable : 4201) -# include +# include #pragma warning(default : 4201) #include "WinAudio.h" @@ -47,7 +47,9 @@ VistaAudio::VistaAudio() : wasapiAudioEvents_(nullptr), mmnAudioEvents_(nullptr), deviceEnumerator_(nullptr), reInit_(false) { - CoInitialize(nullptr); + if (FAILED(CoInitialize(nullptr))) { + throw std::exception("Failed to initialize COM Library"); + } } VistaAudio::~VistaAudio() @@ -86,7 +88,7 @@ bool VistaAudio::Init(HWND hParent) return false; } - if (FAILED(sessionManager2->GetAudioSessionControl(nullptr, 0, + if (FAILED(sessionManager2->GetAudioSessionControl(nullptr, 0, &sessionControl_))) { MessageBox(0, _T("Failed to retrieve session control."), PROGRAM_NAME, MB_ICONERROR); diff --git a/WinMute/WinAudio.h b/WinMute/WinAudio.h index 4ebe0ab..d4fee70 100644 --- a/WinMute/WinAudio.h +++ b/WinMute/WinAudio.h @@ -42,13 +42,13 @@ public: virtual bool IsMuted() = 0; virtual void Mute() = 0; virtual void UnMute() = 0; - virtual ~WinAudio() { }; + virtual ~WinAudio() noexcept { }; }; class XPAudio : public WinAudio { public: XPAudio(); - ~XPAudio(); + ~XPAudio() noexcept; bool Init(HWND hParent); void ShouldReInit(); @@ -77,8 +77,8 @@ private: time_t muteTime_; // non copy-able - XPAudio(const XPAudio& other); - XPAudio& operator=(const XPAudio& other); + XPAudio(const XPAudio& other) = delete; + XPAudio& operator=(const XPAudio& other) = delete; }; // Forwards @@ -91,7 +91,7 @@ class MMNotificationClient; class VistaAudio : public WinAudio { public: VistaAudio(); - ~VistaAudio(); + ~VistaAudio() noexcept; bool Init(HWND hParent); void ShouldReInit(); @@ -113,6 +113,6 @@ private: HWND hParent_; // non copy-able - VistaAudio(const VistaAudio& other); - VistaAudio& operator=(const VistaAudio& other); + VistaAudio(const VistaAudio& other) = delete; + VistaAudio& operator=(const VistaAudio& other) = delete; }; \ No newline at end of file diff --git a/WinMute/WinMain.cpp b/WinMute/WinMain.cpp index e3c5e9c..f95cdf0 100644 --- a/WinMute/WinMain.cpp +++ b/WinMute/WinMain.cpp @@ -35,7 +35,10 @@ POSSIBILITY OF SUCH DAMAGE. HINSTANCE hglobInstance; -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) +int WINAPI wWinMain(_In_ HINSTANCE hInstance, + _In_opt_ HINSTANCE, + _In_ PWSTR, + _In_ int) { HANDLE hMutex = CreateMutex(nullptr, TRUE, _T("BinaryStudiosWinMute")); if (hMutex == NULL) { diff --git a/WinMute/WinMute.vcxproj b/WinMute/WinMute.vcxproj index d396b7b..332e29b 100644 --- a/WinMute/WinMute.vcxproj +++ b/WinMute/WinMute.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -22,29 +22,30 @@ {488617F0-5DD3-42B5-81ED-A1E9B3117551} WinMute Win32Proj + 8.1 Application Unicode true - v120_xp + v140 Application Unicode true - v120 + v140 Application Unicode - v120 + v140_xp Application Unicode - v120 + v140 @@ -101,6 +102,8 @@ Use Level4 EditAndContinue + true + true strsafe.lib;comctl32.lib;WtsApi32.lib;Winmm.lib;%(AdditionalDependencies) @@ -137,6 +140,8 @@ Level4 ProgramDatabase true + true + true strsafe.lib;comctl32.lib;WtsApi32.lib;Winmm.lib;%(AdditionalDependencies) diff --git a/WinMute/XPAudio.cpp b/WinMute/XPAudio.cpp index 66363f9..49cf5bf 100644 --- a/WinMute/XPAudio.cpp +++ b/WinMute/XPAudio.cpp @@ -58,7 +58,7 @@ LRESULT CALLBACK MixerWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) static void PrintMixerError(const tstring& funcName, MMRESULT err) { -//#ifdef _DEBUG +#ifdef _DEBUG std::basic_string error = funcName + L" failed with: "; switch (err) { case MIXERR_INVALCONTROL: @@ -94,10 +94,10 @@ static void PrintMixerError(const tstring& funcName, MMRESULT err) } } MessageBox(0, error.c_str(), 0, MB_ICONERROR); -//#else -// UNREFERENCED_PARAMETER(funcName); -// UNREFERENCED_PARAMETER(err); -//#endif +#else + UNREFERENCED_PARAMETER(funcName); + UNREFERENCED_PARAMETER(err); +#endif } XPAudio::XPAudio() : @@ -291,7 +291,7 @@ void XPAudio::SetDeviceValue(XPAudio::MixerDevice& md, DWORD val) mxcd.cChannels = 1; MIXERCONTROLDETAILS_UNSIGNED mxCtrlDetVolume = { val }; - MIXERCONTROLDETAILS_BOOLEAN mxCtrlDetMuted = { val }; + MIXERCONTROLDETAILS_BOOLEAN mxCtrlDetMuted = { static_cast(val) }; if (md.useMute) { mxcd.dwControlID = md.muteCtrlID;