如何检索类似于 Windows' 内置混音器应用程序中的音频会话名称?

How to retrieve audio session name similar to one in Windows' built-in mixer app?

我正在构建混音器应用程序,需要为每个音频会话获取用户友好的名称。

我试过了:

  1. IAudioSessionControl::GetDisplayName() 方法,但它为每个会话返回空字符串。

  2. 调用QueryFullProcessImageName()GetModuleFileNameEx(),但它们只输出C:\Users\,因为路径中有西里尔字母。但即使他们确实输出了完整路径,我假设它会以 ...\brave.exe 之类的结尾(如果我错了请纠正我),这不是一个用户友好的名称,例如 Brave Browser in Windows' 内置混音器。

  3. 我也试过像这样获取所有进程名称和 PID,然后将它们与会话进程 ID 匹配,这成功地给了我像 chrome.exesteam.exe 这样的名称,但是它们仍然不是我想要的:

    std::vector<std::pair<DWORD, wchar_t*>> processes;
    
        HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        PROCESSENTRY32 entry;
        entry.dwSize = sizeof(PROCESSENTRY32);
    
        Process32First(handle, &entry);
        do {
            processes.emplace_back(entry.th32ProcessID, entry.szExeFile);
        } while (Process32Next(handle, &entry));
    
        CloseHandle(handle);
    

我想要的是像在内置混音器应用程序中那样检索名称,即 SteamChrome BrowserZoom Meetings

有办法实现吗?还是微软在这里使用了某种黑魔法?

Calling QueryFullProcessImageName() and GetModuleFileNameEx(), but they only output C:\Users\ since I have Cyrillic letters in the path.

那你就是没有正确显示路径。西里尔字符的存在不是问题。

I also tried getting all process names and PIDs like this, and later match them to session process IDs, which successfully gave me names like chrome.exe or steam.exe, but they are still, again, not quite what I want

该代码无法正常工作。您正在 std::vector 中存储指向单个 wchar_t[] 缓冲区的指针,该缓冲区在每次循环迭代时都会被修改。您应该存储 std::wstring 而不是 wchar_t*,以便复制每个路径。

What I want is to retrieve names like in the built-in mixer app, ie Steam, Chrome Browser, Zoom Meetings, etc.

获得 EXE 的路径后,您可以使用 GetFileVersionInfo()VerQueryValue() 检索应用程序的人类可读 FileDescription。参见