From 00ae6fe00ddaf48912a63f523cdaecd8143637ab Mon Sep 17 00:00:00 2001 From: lx-s Date: Wed, 2 Oct 2024 08:42:14 +0200 Subject: [PATCH] Changed COM interface definitions --- WinMute/MMNotificationClient.cpp | 22 +++++++++++----------- WinMute/MMNotificationClient.h | 18 +++++++++--------- WinMute/common.h | 1 + 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/WinMute/MMNotificationClient.cpp b/WinMute/MMNotificationClient.cpp index cea710d..a6dacc8 100644 --- a/WinMute/MMNotificationClient.cpp +++ b/WinMute/MMNotificationClient.cpp @@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. class WinAudio; MMNotificationClient::MMNotificationClient(WinAudio* notifyParent) : - ref_(1), pEnumerator_(nullptr), notifyParent_(notifyParent) + ref_count_(1), pEnumerator_(nullptr), notifyParent_(notifyParent) { } @@ -49,21 +49,21 @@ MMNotificationClient::~MMNotificationClient() SafeRelease(&pEnumerator_); } -ULONG STDMETHODCALLTYPE MMNotificationClient::AddRef() +STDMETHODIMP_(ULONG) MMNotificationClient::AddRef() { - return InterlockedIncrement(&ref_); + return ++ref_count_; } -ULONG STDMETHODCALLTYPE MMNotificationClient::Release() +STDMETHODIMP_(ULONG) MMNotificationClient::Release() { - ULONG ref = InterlockedDecrement(&ref_); + const ULONG ref = --ref_count_; if (ref == 0) { delete this; } return ref; } -HRESULT STDMETHODCALLTYPE MMNotificationClient::QueryInterface( +STDMETHODIMP_(HRESULT) MMNotificationClient::QueryInterface( REFIID riid, VOID** ppvInterface) { if (IID_IUnknown == riid) { @@ -80,13 +80,13 @@ HRESULT STDMETHODCALLTYPE MMNotificationClient::QueryInterface( } -HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDefaultDeviceChanged( +STDMETHODIMP_(HRESULT) MMNotificationClient::OnDefaultDeviceChanged( EDataFlow, ERole, LPCWSTR) { return S_OK; } -HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDeviceId) +STDMETHODIMP_(HRESULT) MMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDeviceId) { if (notifyParent_ && pwstrDeviceId != nullptr) { const auto deviceName = GetFriendlyDeviceName(pwstrDeviceId); @@ -96,7 +96,7 @@ HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDevic return S_OK; } -HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDeviceId) +STDMETHODIMP_(HRESULT) MMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDeviceId) { if (notifyParent_ && pwstrDeviceId != nullptr) { const auto deviceName = GetFriendlyDeviceName(pwstrDeviceId); @@ -106,7 +106,7 @@ HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDev return S_OK; } -HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceStateChanged( +STDMETHODIMP_(HRESULT) MMNotificationClient::OnDeviceStateChanged( LPCWSTR pwstrDeviceId, DWORD dwNewState) { bool notify = true; @@ -136,7 +136,7 @@ HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceStateChanged( return S_OK; } -HRESULT STDMETHODCALLTYPE MMNotificationClient::OnPropertyValueChanged( +STDMETHODIMP_(HRESULT) MMNotificationClient::OnPropertyValueChanged( LPCWSTR, const PROPERTYKEY) { return S_OK; diff --git a/WinMute/MMNotificationClient.h b/WinMute/MMNotificationClient.h index 7452816..acc832c 100644 --- a/WinMute/MMNotificationClient.h +++ b/WinMute/MMNotificationClient.h @@ -42,21 +42,21 @@ public: explicit MMNotificationClient(WinAudio* notifyParent); ~MMNotificationClient(); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, VOID** ppvInterface); + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release(); + STDMETHODIMP_(HRESULT) QueryInterface(REFIID riid, VOID** ppvInterface); - HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow flow, ERole role, + STDMETHODIMP_(HRESULT) OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDeviceId); - HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId); - HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId); - HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR pwstrDeviceId, + STDMETHODIMP_(HRESULT) OnDeviceAdded(LPCWSTR pwstrDeviceId); + STDMETHODIMP_(HRESULT) OnDeviceRemoved(LPCWSTR pwstrDeviceId); + STDMETHODIMP_(HRESULT) OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState); - HRESULT STDMETHODCALLTYPE OnPropertyValueChanged(LPCWSTR pwstrDeviceId, + STDMETHODIMP_(HRESULT) OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key); private: - LONG ref_; + std::atomic ref_count_; IMMDeviceEnumerator* pEnumerator_; WinAudio* notifyParent_; diff --git a/WinMute/common.h b/WinMute/common.h index 30b3267..ecb0c95 100644 --- a/WinMute/common.h +++ b/WinMute/common.h @@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE. #define _WIN32_WINNT 0x0601 #include +#include #include #include #include -- 2.43.0