WASAPI_Notification_Interfaces/IUknownInterface.cpp

55 lines
1006 B
C++

#include "IUknownInterface.h"
class CSessionNotifications : public IAudioSessionNotification
{
private:
LONG m_cRefAll;
HWND m_hwndMain;
~CSessionManager() {};
public:
CSessionManager(HWND hWnd) :
m_cRefAll(1),
m_hwndMain(hWnd)
{}
// IUnknown
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv)
{
if (IID_IUnknown == riid)
{
AddRef();
*ppvInterface = (IUnknown*)this;
}
else if (__uuidof(IAudioSessionNotification) == riid)
{
AddRef();
*ppvInterface = (IAudioSessionNotification*)this;
}
else
{
*ppvInterface = NULL;
return E_NOINTERFACE;
}
return S_OK;
}
ULONG STDMETHODCALLTYPE AddRef()
{
return InterlockedIncrement(&m_cRefAll);
}
ULONG STDMETHODCALLTYPE Release)()
{
ULONG ulRef = InterlockedDecrement(&m_cRefAll);
if (0 == ulRef)
{
delete this;
}
return ulRef;
}
HRESULT OnSessionCreated(IAudioSessionControl* pNewSession)
{
if (pNewSession)
{
PostMessage(m_hwndMain, WM_SESSION_CREATED, 0, 0);
}
}
};