c++ - 调用 GetDisplayName 返回与 GetIconPath 相同的结果

标签 c++ windows audio

我目前有这段代码,遍历默认设备(未显示)的 Audio Session 控件:

int sessionCount;
hr = audioSessionEnumerator->GetCount(&sessionCount);
if (FAILED(hr)) {
    throw HRESULTException("audioSessionEnumerator->GetCount", hr);
}

IAudioSessionControl *audioSessionControl;
for (int i = 0; i < sessionCount; ++i) {
    hr = audioSessionEnumerator->GetSession(i, &audioSessionControl);
    if (FAILED(hr)) {
        throw HRESULTException("audioSessionEnumerator->GetSession", hr);
    }

    LPWSTR displayName;
    hr = audioSessionControl->GetDisplayName(&displayName);
    if (FAILED(hr)) {
        throw HRESULTException("audioSessionControl->GetDisplayName", hr);
    }

    std::wcout << displayName << std::endl;

    CoTaskMemFree(displayName);

    audioSessionControl->Release();
}

audioSessionEnumerator->Release();

我的混音器目前看起来像这样: Mixer

预期的输出是:

Steam Client Bootstrapper
melodysheep - The Face of Creation
System Sounds

然而,看到的输出是:

(blank line)
(blank line)
@%SystemRoot%\System32\AudioSrv.Dll,-202

Output

这与将 GetDisplayName 替换为 GetIconPath 时的输出相同。

上面的代码出现了什么问题导致了这个问题?如果必须显示更多代码,请通知我。

最佳答案

如果您阅读了 GetDisplayName 的备注和 GetIconName在 MSDN 中,您会看到如果没有人设置这些函数,它们可以返回 NULL。 GetIconName 页面还指出,如果 sndvol 应用程序(您有其屏幕截图)实际上会查找主窗口的图标,如果它为 NULL,因此通过归纳法将查找显示名称的主窗口标题,如果它是不存在。

您可能想要查询 IAudioSessionControl2具有 GetProcessId 方法的接口(interface)可能会返回客户端进程 ID。此时您可以使用类似 this 的东西和 this尝试从主窗口中提取值以保持一致。

关于c++ - 调用 GetDisplayName 返回与 GetIconPath 相同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27088100/

相关文章:

c++ - 两个 std::arrays 的交叉部分

c++ - 运行 MFC 应用程序时有没有办法输出到 "console"?

python - Hook 并在 Windows 消息队列中记录 "everything"

C++ 持有多个线程

java - CPU 未列为使用 Windows 的设备

javascript - 无法在if陈述式中定义声音

iphone - 声音播放完毕后执行代码的最佳方式

c++ - 打开MP;嵌套循环之间的 Action

android - 使用 Android 6.0.1 但不是 5.1.1 的 Galaxy S6 上的 Gear VR 应用程序中的 TBE 音频跳过

c++ - 如何在 C++ 中操作和表示二进制数