gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:28:33 25 4
gpt4 key购买 nike

我目前有这段代码,遍历默认设备(未显示)的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com