WASAPI GetDisplayName 返回空白

WASAPI GetDisplayName returns blank

本文关键字:空白 返回 GetDisplayName WASAPI      更新时间:2023-10-16

我正在尝试编写一个与Windows Core Audio和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%System32AudioSrv.Dll,-202"
Session Index 1, ""
Session Index 2, ""
Session Index 3, ""
Press any key to continue . . .

这是 3 个程序都处于活动状态并发出噪音。似乎我可以看到系统声音程序,但没有别的。

感谢您的帮助。

另一个问题的想法。

问题应该与会话本身有关。大多数程序从不命名其会话,因此通常会话没有名称,音频混音器上显示的名称可能是会话所有者进程的窗口标题的名称。

使用 IAudioSessionControl2::GetProcessID 并通过其他 API 获取进程的窗口标题应给出一个合理的名称,类似于混音器中的名称。

IAudioSessionControl::GetDisplayName是正确的

API,它可能会返回非空字符串,但是您可能还会看到字符串确实为空的非活动会话。在您的情况下,您可能会遇到非活动会话、未提供的错误代码或其他不正确的 API 使用。

此代码片段/应用程序枚举会话和轮询以更改卷 - 它打印非空字符串。

CComHeapPtr<WCHAR> pszDisplayName;
ATLENSURE_SUCCEEDED(pSessionControl->GetDisplayName(&pszDisplayName));
_tprintf(_T("nSessionIndex %d, pszDisplayName "%s"n"), 
    nSessionIndex, CString(pszDisplayName));
C:AudioSessionVolumeNotificationDebug>AudioSessionVolumeNotification.exe
nSessionCount 5
nSessionIndex 0, pszDisplayName "@%SystemRoot%System32AudioSrv.Dll,-202"
nSessionIndex 1, pszDisplayName "Mozilla Firefox"
nSessionIndex 2, pszDisplayName "Mozilla Thunderbird"
nSessionIndex 3, pszDisplayName "Mozilla Firefox"
nSessionIndex 4, pszDisplayName ""