WASAPI GetDisplayName 返回空白
WASAPI GetDisplayName returns blank
我正在尝试编写一个与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 ""
相关文章:
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 什么时候在C++中返回常量引用是个好主意
- 你能重载对象变量名本身返回的内容吗
- 为什么 Serial.println(<char[]>);返回随机字符?
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何获取std::result_of函数的返回类型
- TCP 服务器/客户端:客户端 recv() 返回空白缓冲区
- QML 函数始终返回空白
- 字符串:: substr()返回一个空白字符串
- 返回空白
- QT 5.4 QPrinterInfo::printerName返回空白
- OpenCV VideoCaptures 有时会返回空白帧
- Qt5.4 QOpenGLFramebufferObject toImage 返回空白图像
- 为什么从文件输入中读取 std::string 会返回空白
- WASAPI GetDisplayName 返回空白
- Getline只返回空白
- 我在我的程序中添加了一个void函数,它不接受任何参数,现在我的程序在运行时只返回一个空白终端
- ReadFile()返回一个空白数据
- QtCreator QMediaPlayer元数据返回空白QString
- 为什么这段代码在试图将.txt放入向量并对其进行cout时会返回空白控制台