views:

397

answers:

3

I just had a very long tech support call because a customer didn't have a Mic on their laptop. (Stupid me: they said they'd used the mic earlier and I have never heard of a laptop not having a Mic).

I'm wondering if there is a way to detect whether there is a Microphone (recording capability) on Windows XP, Vista, 7.

(I've got error handling enabled and it logs the error and then exits the Function but the app just crashes on Windows 7 if there's no Microphone. )

A: 

I think the only way you will be able to do this in VB 6 is through Direct X:

http://msdn.microsoft.com/en-us/library/bb318770(VS.85).aspx

You can check this out:

http://msdn.microsoft.com/en-us/library/bb280815(VS.85).aspx

CaptureDevices Collection Class (Microsoft.DirectX.DirectSound)

http://msdn.microsoft.com/en-us/library/ms810619.aspx

you can also call dxdiag..

James Campbell
I haven't tested this but it looks like the best answer (for VB6).
Clay Nichols
+1  A: 

I'd use IMMDeviceEnumerator::GetDefaultAudioEndpoint - this returns the default audio device for the specified role and data flow.

In particular, you would use:

    CComPtr<IMMDeviceEnumerator> pEnumerator;
    CComPtr<IMMDevice> pDevice;

    hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL,
           CLSCTX_ALL, IID_PPV_ARGS(&pEnumerator));
    if (SUCCEEDED(hr))
    {
        hr = pEnumerator->GetDefaultAudioEndpoint(eCapture, eConsole, &pDevice);
    }
    if (!pDevice || hr == ERROR_NOT_FOUND)
    {
           // no microphone
    }
Eric Brown
Original post tagged VB6....
Rob Cowell
+1  A: 

Check out System Tray Audio Device Switcher

In this VB source code you will an example on how to enumerate audio I/O devices.

stacker