views:

370

answers:

3

How do I detect if the system has a default recording device installed? I bet this can be done through some calls to the Win32 API, anyone has any experience with this?

I'm talking about doing this through code, not by opening the control panel and taking a look under sound options.

A: 

There is an Open Source Audio API called PortAudio that has a method you could use. I think the method is called Pa_GetDeviceInfo() or something.

Espo
+1  A: 

Using the DirectX SDK, you can call DirectSoundCaptureEnumerate, which will call your DSEnumCallback function for each DirectSoundCapture device on the system. The first parameter passed to your DSEnumCallback is an LPGUID, which is the "Address of the GUID that identifies the device being enumerated, or NULL for the primary device".

If all you need to do is find out if a recording device is present (I don't think this is good enough if you really need to know the default device), you can use waveInGetNumDevs:

#include <tchar.h>
#include <windows.h>
#include "mmsystem.h"

int _tmain( int argc, wchar_t *argv[] )
{
    UINT deviceCount = waveInGetNumDevs();

    if ( deviceCount > 0 )
    {
        for ( int i = 0; i < deviceCount; i++ )
        {
            WAVEINCAPSW waveInCaps;

            waveInGetDevCapsW( i, &waveInCaps, sizeof( WAVEINCAPS ) );

            // do some stuff with waveInCaps...
        }
    }

    return 0;
}
Jeff Hillman
A: 

The win32 api has a function called waveInGetNumDevs for it.

Lars Truijens