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 t开发者_StackOverflow社区he Function but the app just crashes on Windows 7 if there's no Microphone. )
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
}
Check out System Tray Audio Device Switcher
In this VB source code you will an example on how to enumerate audio I/O devices.
in C++
#include "stdafx.h"
#include "Mmdeviceapi.h"
#include <atlbase.h>
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
CComPtr<IMMDeviceEnumerator> pEnumerator = NULL;
CComPtr<IMMDevice> pDevice;
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
HRESULT hr = CoCreateInstance(
CLSID_MMDeviceEnumerator, NULL,
CLSCTX_ALL, IID_IMMDeviceEnumerator,
(void**)&pEnumerator);
if (FAILED(hr))
{
printf("failed");
}
else
{
hr = pEnumerator->GetDefaultAudioEndpoint(eCapture, eConsole, &pDevice);
if (!pDevice || hr == ERROR_NOT_FOUND)
{
printf("no microphone");
}
else
{
printf("microphone present");
}
}
return 0;
}
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..
精彩评论