Sample: find out if your default audio playback and audio capture devices are on the same hardware


This blog post has moved to https://matthewvaneerde.wordpress.com/2008/06/13/sample-find-out-if-your-default-audio-playback-and-audio-capture-devices-are-on-the-same-hardware/

Comments (7)

  1. JMK says:

    This is a perfect example of how something should be much simpler than it is.  That’s a ridiculous amount of code!

  2. Yes… I agree that the DeviceTopology "connector dance" is a little cumbersome, and the PKEY_Device_InstanceId trick starts to smack of voodoo.

    I considered writing a helper function

    HRESULT InstanceId_From_IMMDevice(IMMDevice *pEndpoint, LPWSTR *ppwszInstanceId);

    which would cut the length of the program by about a third, but I think the sample is more readable (though longer) the way I did it.

    On the other hand, the code posted is fully functional, under 200 lines, and that’s with full logging, error checking, comments, and denormalization.

    What are the scenarios when you need to know what hardware is behind the audio endpoint?

  3. khushboo says:

    can you please tell me …….from where to get this DeviceTopology.h header file cz it seems not to be present…..

  4. Download the Windows SDK.

    http://blogs.msdn.com/windowssdk/

    On my machine devicetopology.h is in the following folder:

    C:Program FilesMicrosoft SDKsWindowsv6.0AInclude

  5. Jonny says:

    > What are the scenarios when you need

    > to know what hardware is behind the audio endpoint?

    I’m just rambling here, but hey:

    Any app that provides voice communication, esp. games might be interested in knowing that. Users do care about their default output device, but a lot of errors in voice com stem from improperly set input configuration. If the user is already using e.g. a USB headset for output, the game can make a safe bet by using the headset’s microphone. Or at least point the user to mismatching configs.

  6. Jyothy says:

    Hi Matthew,

    Can you please help us to find the parent id and hardware id of the audio device connected to the PC?

  7. @Jyothy check out the Windows.Devices.Enumeration sample here. You can use the

    github.com/…/DeviceEnumeration

    There are four "selectors" under Windows.Media.Devices.MediaDevice which correspond to "the default audio render device", "the default audio capture device", "all audio render devices", and "all audio capture devices".

    msdn.microsoft.com/…/windows.media.devices.mediadevice.aspx

    You can traverse the device parent-child tree using the System.Devices.Parent property msdn.microsoft.com/…/mt187351.aspx

    But more interesting is the System.Devices.ContainerId property, which tells you what other devices are on the same hardware.

Skip to main content