]> repos.lx-s.de Git - winmute.git/commitdiff
Upgraded project to Visual Studio 2015. Fixed analyzer warnings.
authorlx-s <lx-s@users.noreply.github.com>
Thu, 11 Aug 2016 09:06:54 +0000 (11:06 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Thu, 11 Aug 2016 09:06:54 +0000 (11:06 +0200)
ScreensaverNotify/ScreensaverNotify.vcxproj
WinMute/TrayIcon.cpp
WinMute/Utility.cpp
WinMute/VistaAudio.cpp
WinMute/WinAudio.h
WinMute/WinMain.cpp
WinMute/WinMute.vcxproj
WinMute/XPAudio.cpp

index 3ece1130f830f0b3ba8097eb32b97928e073f9f8..6bb6e1009489348375cbcb877a21eda954fa1a28 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
       <Configuration>Debug</Configuration>
     <Keyword>Win32Proj</Keyword>
     <RootNamespace>ScreensaverNotify</RootNamespace>
     <ProjectName>ScreensaverNotify</ProjectName>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v120_xp</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
@@ -58,6 +59,7 @@
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;WINMUTEDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <SDLCheck>true</SDLCheck>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
+      <TreatWarningAsError>true</TreatWarningAsError>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -75,6 +77,7 @@
       <SDLCheck>true</SDLCheck>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <TreatWarningAsError>true</TreatWarningAsError>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
index ac3594e2f8bb17212d10bd514920476b37f43e43..156b67ae83e4a512688f0c577d3cdf3457073730 100644 (file)
@@ -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;
 }
index 79543c1540260123cec7219a0709fd3309b1fc98..197f5eaf387b2558cea5e782f5fdc8f07d4d317a 100644 (file)
@@ -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<LPCTSTR>(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<TCHAR*>(lpMsgBuf));
 
          MessageBox(nullptr, static_cast<LPCTSTR>(lpDisplayBuf), _T("Error"),
-                    MB_ICONERROR | MB_OK); 
+                    MB_ICONERROR | MB_OK);
 
          LocalFree(lpDisplayBuf);
       }
index a17f90d80c5f367d0d6b93c7d52795ba769d4baf..4cf6c4a1793ef7913a0c5406421ad42681a102c7 100644 (file)
@@ -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 <mmdeviceapi.h>
 
 #pragma warning(disable : 4201)
-#  include <endpointvolume.h> 
+#  include <endpointvolume.h>
 #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);
index 4ebe0ab1c3dc44dff6750d71f589d2fb3c6f20f7..d4fee7027f3d3068876464ddcac4ea3eb1b50cc6 100644 (file)
@@ -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
index e3c5e9c2af6d8bea0d97210fd023357b53e4ae6d..f95cdf0bfeb7f71998910fecdb7d68a0a779c9e7 100644 (file)
@@ -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) {
index d396b7b7c41b67041bbb8dd50285eeb514cb56ef..332e29bfbffbbffb52fe108451d659339734b364 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
       <Configuration>Debug</Configuration>
     <ProjectGuid>{488617F0-5DD3-42B5-81ED-A1E9B3117551}</ProjectGuid>
     <RootNamespace>WinMute</RootNamespace>
     <Keyword>Win32Proj</Keyword>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>v120_xp</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140_xp</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
       <PrecompiledHeader>Use</PrecompiledHeader>
       <WarningLevel>Level4</WarningLevel>
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <TreatWarningAsError>true</TreatWarningAsError>
+      <SDLCheck>true</SDLCheck>
     </ClCompile>
     <Link>
       <AdditionalDependencies>strsafe.lib;comctl32.lib;WtsApi32.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <WarningLevel>Level4</WarningLevel>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
+      <TreatWarningAsError>true</TreatWarningAsError>
+      <SDLCheck>true</SDLCheck>
     </ClCompile>
     <Link>
       <AdditionalDependencies>strsafe.lib;comctl32.lib;WtsApi32.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
index 66363f919feecaab1b65e341dd2517f02902c22a..49cf5bf7f2d2b17712bee997ef40e4526e73f4f0 100644 (file)
@@ -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<TCHAR> 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<LONG>(val) };
 
    if (md.useMute) {
       mxcd.dwControlID = md.muteCtrlID;