c++ - Windows 应用程序音量混合器

标签 c++ windows wasapi mixer

我想列出显示在 windows 音量混合器中的应用程序。

在此示例中,“sons systeme”、“Windows”和“spotify” enter image description here 我写了一些代码,我能够计算并列出这些应用程序。问题是我无法获取他们的名字或他们的图标路径 这是输出:

Session Name:
Icon path Name:
Session Name:
Icon path Name:
Session Name:
Icon path Name:
Session Name: @%SystemRoot%\System32\AudioSrv.Dll,-202
Icon path Name: @%SystemRoot%\System32\AudioSrv.Dll,-203

我不明白为什么我无法获取此类数据。

这是我的代码:

 IMMDevice* pDevice = NULL;
IMMDeviceEnumerator* pEnumerator = NULL;
IAudioSessionControl* pSessionControl = NULL;
IAudioSessionControl2* pSessionControl2 = NULL;
IAudioSessionManager2* pSessionManager = NULL;

hr = CoInitialize(NULL);

// Create the device enumerator.
hr = CoCreateInstance(
            __uuidof(MMDeviceEnumerator),
            NULL, CLSCTX_ALL,
            __uuidof(IMMDeviceEnumerator),
            (void**)&pEnumerator);

// Get the default audio device.
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
hr = pDevice->Activate(__uuidof(IAudioSessionManager2),
                             CLSCTX_ALL,
                             NULL, (void**)&pSessionManager);

hr = pSessionManager->GetAudioSessionControl(0, FALSE, &pSessionControl);

// Get the extended session control interface pointer.
hr = pSessionControl->QueryInterface(__uuidof(IAudioSessionControl2), (void**) &pSessionControl2);

// Check whether this is a system sound.
hr = pSessionControl2->IsSystemSoundsSession();

int cbSessionCount = 0;
LPWSTR pswSession = NULL;

IAudioSessionEnumerator* pSessionList = NULL;

hr = pSessionManager->GetSessionEnumerator(&pSessionList);
hr = pSessionList->GetCount(&cbSessionCount);
std::cout << cbSessionCount << std::endl;
for (int index = 0 ; index < cbSessionCount ; index++)
{
    hr = pSessionList->GetSession(index, &pSessionControl);
    hr = pSessionControl->GetDisplayName(&pswSession);
    std::wcout << "Session Name: " <<  pswSession << std::endl;
    hr = pSessionControl->GetIconPath(&pswSession);
    std::wcout << "Icon path Name: " <<  pswSession << std::endl;
}

最佳答案

您可以使用 ProcessID 检索名称

DWORD procID;
pSessionControl2->GetProcessId(&procID);

然后使用 ProcessID,您可以获得程序的句柄并找到名称和图标。

关于c++ - Windows 应用程序音量混合器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48390234/

相关文章:

c++ - 使用 C++ 类时出现巨大的删除错误

mysql - Docker:$'\r':在 Windows 上找不到命令

WASAPI AudioClient.GetMixFormat() 返回 AUDCLNT_E_NOT_INITIALIZED

windows - Windows 上的 kubectl diff 返回错误 : executable file not found in PATH

linux - Windows 和 Linux 上的 maven-antrun-plugin

windows - 如何从 MMDevice 获取 channel 数?

c++ - 使用 WASAPI 捕获蓝牙音频数据

c++ - 访问基类的私有(private)变量时派生类出错

c++ - 为什么 VC++ 编译代码而 clang 不编译?

c++ - 确定基于四元数调整方向所需的角速度