Sample: how to enumerate waveIn and waveOut devices on your system


This shows how to call waveInGetNumDevs, waveInGetDevCaps, waveOutGetNumDevs, and waveOutGetDevCaps.

// main.cpp

#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>

#define LOG(format, …) wprintf(format L”\n”, __VA_ARGS__)

int _cdecl wmain() {

    UINT devs = waveInGetNumDevs();
    LOG(L”waveIn devices: %u”, devs);
    for (UINT dev = 0; dev < devs; dev++) {
        WAVEINCAPS caps = {};
        MMRESULT mmr = waveInGetDevCaps(dev, &caps, sizeof(caps));
       
        if (MMSYSERR_NOERROR != mmr) {
             LOG(L”waveInGetDevCaps failed: mmr = 0x%08x”, mmr);
             return mmr;
        }
       
        LOG(
            L”– waveIn device #%u –\n”
            L”Manufacturer ID: %u\n”
            L”Product ID: %u\n”
            L”Version: %u.%u\n”
            L”Product Name: %s\n”
            L”Formats: 0x%x\n”
            L”Channels: %u\n”
            L”Reserved: %u\n”
            ,
            dev,
            caps.wMid,
            caps.wPid,
            caps.vDriverVersion / 256, caps.vDriverVersion % 256,
            caps.szPname,
            caps.dwFormats,
            caps.wChannels,
            caps.wReserved1
        );
    }

    devs = waveOutGetNumDevs();
    LOG(L”waveOut devices: %u”, devs);
    for (UINT dev = 0; dev < devs; dev++) {
        WAVEOUTCAPS caps = {};
        MMRESULT mmr = waveOutGetDevCaps(dev, &caps, sizeof(caps));
       
        if (MMSYSERR_NOERROR != mmr) {
             LOG(L”waveOutGetDevCaps failed: mmr = 0x%08x”, mmr);
             return mmr;
        }
       
        LOG(
            L”– waveOut device #%u –\n”
            L”Manufacturer ID: %u\n”
            L”Product ID: %u\n”
            L”Version: %u.%u\n”
            L”Product Name: %s\n”
            L”Formats: 0x%x\n”
            L”Channels: %u\n”
            L”Reserved: %u\n”
            L”Support: 0x%x\n”
            L”%s%s%s%s%s”
            ,
            dev,
            caps.wMid,
            caps.wPid,
            caps.vDriverVersion / 256, caps.vDriverVersion % 256,
            caps.szPname,
            caps.dwFormats,
            caps.wChannels,
            caps.wReserved1,
            caps.dwSupport,
                ((caps.dwSupport & WAVECAPS_LRVOLUME) ?       L”\tWAVECAPS_LRVOLUME\n” :       L””),
                ((caps.dwSupport & WAVECAPS_PITCH) ?          L”\tWAVECAPS_PITCH\n” :          L””),
                ((caps.dwSupport & WAVECAPS_PLAYBACKRATE) ?   L”\tWAVECAPS_PLAYBACKRATE\n” :   L””),
                ((caps.dwSupport & WAVECAPS_VOLUME) ?         L”\tWAVECAPS_VOLUME\n” :         L””),
                ((caps.dwSupport & WAVECAPS_SAMPLEACCURATE) ? L”\tWAVECAPS_SAMPLEACCURATE\n” : L””)
        );
    }

    return 0;
}

On my system this outputs:

waveIn devices: 3
— waveIn device #0 —
Manufacturer ID: 1
Product ID: 65535
Version: 0.0
Product Name: Microphone (High Definition Aud
Formats: 0xfffff
Channels: 2
Reserved: 0

— waveIn device #1 —
Manufacturer ID: 1
Product ID: 65535
Version: 0.0
Product Name: Digital Audio (S/PDIF) (High De
Formats: 0xfffff
Channels: 2
Reserved: 0

— waveIn device #2 —
Manufacturer ID: 1
Product ID: 65535
Version: 0.0
Product Name: CD Audio (High Definition Audio
Formats: 0xfffff
Channels: 2
Reserved: 0

waveOut devices: 2
— waveOut device #0 —
Manufacturer ID: 1
Product ID: 65535
Version: 0.0
Product Name: Headphones (High Definition Aud
Formats: 0xfffff
Channels: 2
Reserved: 0
Support: 0x2e
 WAVECAPS_LRVOLUME
 WAVECAPS_PLAYBACKRATE
 WAVECAPS_VOLUME
 WAVECAPS_SAMPLEACCURATE

— waveOut device #1 —
Manufacturer ID: 1
Product ID: 65535
Version: 0.0
Product Name: Digital Audio (S/PDIF) (High De
Formats: 0xfffff
Channels: 2
Reserved: 0
Support: 0x2e
 WAVECAPS_LRVOLUME
 WAVECAPS_PLAYBACKRATE
 WAVECAPS_VOLUME
 WAVECAPS_SAMPLEACCURATE

 

Source and binaries attached.

EDIT September 22 2015: moved source to github https://github.com/mvaneerde/blog/tree/master/waveenum

waveenum.zip

Comments (4)

  1. Roman R. says:

    In a year of 2012… :)

  2. Actually this was in response to a forum question that was posted yesterday:

    social.msdn.microsoft.com/…/06a75050-64be-4cac-8b7b-e5f51fdd3597

  3. Parallel says:

    This api can not enumerate the disabled device~ Sad

  4. You can use IMMDeviceEnumerator::EnumAudioEndpoints to get a list of disabled devices.

Skip to main content