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: %un"
            L"Product ID: %un"
            L"Version: %u.%un"
            L"Product Name: %sn"
            L"Formats: 0x%xn"
            L"Channels: %un"
            L"Reserved: %un"
            ,
            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: %un"
            L"Product ID: %un"
            L"Version: %u.%un"
            L"Product Name: %sn"
            L"Formats: 0x%xn"
            L"Channels: %un"
            L"Reserved: %un"
            L"Support: 0x%xn"
            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_LRVOLUMEn" :       L""),
                ((caps.dwSupport & WAVECAPS_PITCH) ?          L"tWAVECAPS_PITCHn" :          L""),
                ((caps.dwSupport & WAVECAPS_PLAYBACKRATE) ?   L"tWAVECAPS_PLAYBACKRATEn" :   L""),
                ((caps.dwSupport & WAVECAPS_VOLUME) ?         L"tWAVECAPS_VOLUMEn" :         L""),
                ((caps.dwSupport & WAVECAPS_SAMPLEACCURATE) ? L"tWAVECAPS_SAMPLEACCURATEn" : 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

Browse source

Download waveenum.exe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s