既然我已经安装了 RC,我正在挑选一些我在 Windows 7 Beta 中搞砸的实验性代码。
IAudioSessionManager2
基本上,我正在努力让IAudioSessionNotification
我的小应用了解每个创建的新音频会话。
AudioListener
(公共)中的关键代码IAudioSessionNotification
:
//This is mostly lifted from MSDN
HRESULT STDMETHODCALLTYPE AudioListener::QueryInterface(REFIID riid, void** ppvObject)
{
if(riid == __uuidof(IUnknown))
{
*ppvObject = (IUnknown*)this;
return S_OK;
}
if(riid == __uuidof(IAudioSessionNotification))
{
*ppvObject = (IAudioSessionNotification*)this;
return S_OK;
}
*ppvObject = NULL;
return E_NOINTERFACE;
}
//m_hwnd, and WM_SESSION_CREATED are set to good values
//WM_SESSION_CREATEd via RegisterWindowMessage(...)
HRESULT STDMETHODCALLTYPE AudioListener::OnSessionCreated(IAudioSessionControl *pSession)
{
PostMessage(m_hwnd, WM_SESSION_CREATED, (WPARAM)pSession, 0);
return S_OK;
}
注册我的听众的代码:
BOOL RegisterMonitor(HWND target)
{
BOOL success = false;
HRESULT res;
IMMDevice* pDevice;
IMMDeviceEnumerator* pEnumerator;
SESSION_LISTENER = NULL;
SESSION = NULL;
res = CoInitialize(NULL);
if(res != S_OK && res != S_FALSE)
return false;
SESSION_LISTENER = new AudioListener(target);
res = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
if(res != S_OK) goto Exit;
res = pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDevice);
if(res != S_OK) goto Exit;
res = pDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&SESSION);
if(res != S_OK) goto Exit;
res = SESSION->RegisterSessionNotification(SESSION_LISTENER);
if(res != S_OK) goto Exit;
success = true;
Exit:
SAFE_RELEASE(pEnumerator);
SAFE_RELEASE(pDevice);
if(!success)
{
SAFE_RELEASE(SESSION_LISTENER);
SAFE_RELEASE(SESSION);
}
return success;
}
RegisterMonitor(...)
返回 true,但从未收到任何通知。我一直在通过启动具有轻微音效的小应用程序并触发它们(Soltaire、Minesweeper 等)进行测试,确认它们会在SndVol
我期望看到通知时出现。
基本上,有没有人看到我做错了什么?