我正在尝试写一个程序,与Windows核心音频和WASAPI接口。我在下面的几行中遇到了困难。
CComHeapPtr<WCHAR> name;
hr = pAudioSessionControl->GetDisplayName(&name);
if (FAILED(hr)) {
LOG(L"IAudioSessionControl::GetDisplayName() failed: hr = 0x%08x", hr);
return -__LINE__; }
_tprintf(_T("Session Index %d, \"%s\"\n"), i, CString(name));输出:
Session Index 0, "@%SystemRoot%\System32\AudioSrv.Dll,-202"
Session Index 1, ""
Session Index 2, ""
Session Index 3, ""
Press any key to continue . . .这是3个程序都处于活动状态,正在制造噪音。好像我能看到系统的声音程序,但看不到其他的。
谢谢你的帮助。
发布于 2017-08-06 01:35:01
来自another question的想法。
问题应该是会话本身。大多数程序从不命名它们的会话,所以通常会话没有名称,音频混音器上显示的名称可能是会话所有者进程的窗口标题的名称。
使用IAudioSessionControl2::GetProcessID并通过其他API获取进程的窗口标题应该会给出一个合理的名称,类似于混音器中的名称。
发布于 2014-11-16 07:19:16
IAudioSessionControl::GetDisplayName是合适的API,它可能会返回非空字符串,但是您也可能会看到字符串确实为空的非活动会话。在您的情况下,您可能会遇到非活动会话、未提供的错误代码或其他不正确的API使用。
This code snippet/application枚举会话并轮询卷的变化-它打印非空字符串。
CComHeapPtr<WCHAR> pszDisplayName;
ATLENSURE_SUCCEEDED(pSessionControl->GetDisplayName(&pszDisplayName));
_tprintf(_T("nSessionIndex %d, pszDisplayName \"%s\"\n"),
nSessionIndex, CString(pszDisplayName));C:\AudioSessionVolumeNotification\Debug>AudioSessionVolumeNotification.exe
nSessionCount 5
nSessionIndex 0, pszDisplayName "@%SystemRoot%\System32\AudioSrv.Dll,-202"
nSessionIndex 1, pszDisplayName "Mozilla Firefox"
nSessionIndex 2, pszDisplayName "Mozilla Thunderbird"
nSessionIndex 3, pszDisplayName "Mozilla Firefox"
nSessionIndex 4, pszDisplayName ""https://stackoverflow.com/questions/26948290
复制相似问题