【问题标题】:Calling GetDisplayName returns same result as GetIconPath调用 GetDisplayName 返回与 GetIconPath 相同的结果
【发布时间】:2014-11-23 10:48:21
【问题描述】:

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

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();

我的混音器目前如下所示:

预期的输出是:

Steam Client Bootstrapper
melodysheep - The Face of Creation
System Sounds

但是,看到的输出是:

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

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

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

【问题讨论】:

    标签: c++ windows audio


    【解决方案1】:

    如果您阅读 MSDN 中对 GetDisplayNameGetIconName 的注释,您会发现如果没有人设置它们,这些函数可以返回 NULL。 GetIconName 页面还指出,如果主窗口的图标为 NULL,sndvol 应用程序(您已经获得了屏幕截图)实际上会查找主窗口的图标,因此如果显示名称,则通过归纳将查找主窗口标题不存在。

    您可能想要查询IAudioSessionControl2 接口,该接口有一个GetProcessId 方法,该方法可能会返回客户端进程ID。此时,您可以使用thisthis 之类的东西来尝试从主窗口中提取值以保持一致。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-02
      • 2013-08-09
      • 1970-01-01
      • 2010-12-22
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多