Question

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.

Was it helpful?

Solution

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;
}

OTHER TIPS

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.

The win32 api has a function called waveInGetNumDevs for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top