C++ Windows应用程序音量混合器

C++ Windows应用程序音量混合器,c++,windows,wasapi,mixer,C++,Windows,Wasapi,Mixer,我想列出windows volume mixer中显示的应用程序 在本例中,“sons systeme”、“Windows”和“spotify” 我写了一些代码,我能够计算并列出这些应用程序。问题是我无法获取他们的名字或图标路径 以下是输出: Session Name: Icon path Name: Session Name: Icon path Name: Session Name: Icon path Name: Session Name: @%SystemRoot%\System32\A

我想列出windows volume mixer中显示的应用程序

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

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;
}
IMMDevice*pDevice=NULL;
IMMDeviceEnumerator*pEnumerator=NULL;
IAAudioSessionControl*PSSessionControl=NULL;
IAAudioSessionControl2*PSSessionControl2=NULL;
IAudioSessionManager2*pSessionManager=NULL;
hr=协同初始化(空);
//创建设备枚举器。
hr=CoCreateInstance(
__uuidof(MMDeviceEnumerator),
空,CLSCTX_ALL,
__uuidof(IMMDeviceEnumerator),
(void**)和pEnumerator);
//获取默认的音频设备。
hr=pEnumerator->GetDefaultAudioEndpoint(eRender、eConsole和pDevice);
hr=pDevice->Activate(u_uidof(IAudioSessionManager2),
CLSCTX_ALL,
无效,(无效**)和pSessionManager);
hr=pSessionManager->GetAudioSessionControl(0,FALSE和pSessionControl);
//获取扩展会话控制接口指针。
hr=pSessionControl->QueryInterface(u uuidof(IAudioSessionControl2),(void**)和pSessionControl2);
//检查这是否是系统声音。
hr=pSessionControl2->IsSystemSoundsSession();
int cbSessionCount=0;
LPWSTR pswSession=NULL;
IAudioSessionEnumerator*pSessionList=NULL;
hr=pSessionManager->GetSessionNumber(&pSessionList);
hr=pSessionList->GetCount(&cbSessionCount);
std::cout GetDisplayName(&pswSession);

std::wcout您可以使用ProcessID检索名称

DWORD procID;
pSessionControl2->GetProcessId(&procID);
然后使用ProcessID可以获得程序的句柄并找到名称和图标