class WinAudio;
MMNotificationClient::MMNotificationClient(WinAudio* notifyParent) :
- ref_(1), pEnumerator_(nullptr), notifyParent_(notifyParent)
+ ref_count_(1), pEnumerator_(nullptr), notifyParent_(notifyParent)
{
}
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) {
}
-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);
return S_OK;
}
-HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDeviceId)
+STDMETHODIMP_(HRESULT) MMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDeviceId)
{
if (notifyParent_ && pwstrDeviceId != nullptr) {
const auto deviceName = GetFriendlyDeviceName(pwstrDeviceId);
return S_OK;
}
-HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceStateChanged(
+STDMETHODIMP_(HRESULT) MMNotificationClient::OnDeviceStateChanged(
LPCWSTR pwstrDeviceId, DWORD dwNewState)
{
bool notify = true;
return S_OK;
}
-HRESULT STDMETHODCALLTYPE MMNotificationClient::OnPropertyValueChanged(
+STDMETHODIMP_(HRESULT) MMNotificationClient::OnPropertyValueChanged(
LPCWSTR, const PROPERTYKEY)
{
return S_OK;
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<LONG> ref_count_;
IMMDeviceEnumerator* pEnumerator_;
WinAudio* notifyParent_;