DirectX SDK |
For an application that is simply going to capture sounds through the user's preferred capture device, you don't need to enumerate the available devices. When you create the DirectSoundCapture object with NULL as the device identifier, the interface will automatically be associated with the default device if one is present. (If no device driver is present, the call to the DirectSoundCaptureCreate function fails.)
For an application that is simply going to capture sounds through the user's preferred capture device, you don't need to enumerate the available devices. When you create the DirectSoundCapture object with an empty string as the device identifier, the interface will automatically be associated with the default device if one is present. (If no device driver is present, the call to the DirectX7.DirectSoundCaptureCreate function fails.)
However, if you are looking for a particular kind of device or wish to offer the user a choice of devices, you must enumerate the devices available on the system.
Enumeration serves three purposes:
To enumerate devices you must first set up a callback function that will be called each time DirectSound finds a device. You can do anything you want within this function, and you can give it any name, but you must declare it in the same form as DSEnumCallback, a prototype in this documentation. The callback function must return TRUE if enumeration is to continue, or FALSE otherwise (for instance, after finding a device with the capabilities you need).
For a sample callback function, see Enumeration of Sound Devices. Note that a GUID for each device is obtained as one of the parameters to this function.
The enumeration is set in motion by using the DirectSoundCaptureEnumerate function:
DWORD pv; // Any 32-bit value. HRESULT hr = DirectSoundCaptureEnumerate( (LPDSENUMCALLBACK)DSEnumProc, &pv)
To enumerate devices you must first call the DirectX7.GetDSCaptureEnum method to create a DirectSoundEnum object. The DirectSoundEnum object is filled with a collection of devices which you can then query each individual device with the DirectSoundEnum.GetCount, DirectSoundEnum.GetDescription, DirectSoundEnum.GetGuid and DirectSoundEnum.GetName methods.