2

In the Sound Control Panel in Windows, and in the Volume Mixer, all audio devices have a specific icon set.

Is it possible to get which icon is set for a device through the Windows API?

Sound Control Panel Volume Mixer

nixx
  • 41
  • 3
  • 1
    If you look that answer here: https://stackoverflow.com/questions/20938934/controlling-applications-volume-by-process-id the AudioSession class has an IconPath property. – Simon Mourier Jan 19 '20 at 16:50
  • I tried that out after your suggestion, but it is not what I'm looking for. For one, it operates on audio sessions, not audio devices. For two, according to the [MSDN documentation](https://learn.microsoft.com/en-gb/windows/win32/api/audiopolicy/nf-audiopolicy-iaudiosessioncontrol-geticonpath) "If a client has not called IAudioSessionControl::SetIconPath to set the display icon, the string will be empty." – nixx Jan 20 '20 at 17:27
  • I believe what you see in the mixer is audio sessions, not devices. Anyway, in my code, I just didn't exposed all properties of audio devices but you can get them using the `Properties` dictionary. I've just modified my code and added an `IconPath` property on `AudioDevice` class. https://learn.microsoft.com/en-us/windows-hardware/drivers/install/devpkey-deviceclass-iconpath – Simon Mourier Jan 20 '20 at 18:00
  • Yes, you're right. I'm sure I tried that, but whatever, this does work. – nixx Jan 21 '20 at 22:48

1 Answers1

2

As suggested by Simon Mourier in the comments above, there is a PKEY that can access that data.

You can follow along with most of this sample and just replace PKEY_Device_FriendlyNamewith PKEY_DeviceClass_IconPath.

In short, it's something like this:

    // [...]

    IMMDevice *pDevice; // the device you want to look up
    HRESULT hr = S_OK;
    IPropertyStore *pProps = NULL;
    PROPVARIANT varName;

    hr = pDevice->OpenPropertyStore(STGM_READ, &pProps);
    EXIT_ON_ERROR(hr);

    PropVariantInit(&varName);

    hr = pProps->GetValue(PKEY_DeviceClass_IconPath, &varName);
    EXIT_ON_ERROR(hr);

    // [...]
nixx
  • 41
  • 3