You can create a capture device object by calling the DirectSoundCaptureCreate8 or DirectSoundFullDuplexCreate8 function. Both of these functions get a pointer to the IDirectSoundCapture8 interface.
The Lpcguid parameter of the directsoundcapturecreate or the Pcguidrenderdevice parameter of the DirectSoundFullDuplexCreate8 can be a GUID obtained by the enumeration, Or one of the following predefined GUIDs:
Guid |
Description |
Dsdevid_defaultcapture |
The system's default sound capture device. You can also specify a device by passing a null pointer instead of a device GUID. |
Dsdevid_defaultvoicecapture |
The default sound communication device. Typically, this is a secondary device such as a USB headset with a microphone. |
If there is currently no device driver, the call fails.
You can also use the CoCreateInstance function to create an object. This process is similar to creating a device object. The steps are as follows:
1. Initializing COM objects by calling the CoInitializeEx function at application startup
Code
HRESULT hr = CoInitializeEx(NULL, 0);
if (FAILED(hr))
{
ErrorHandler(hr); // Add error-handling here.
}
2. Create device objects by calling the CoCreateInstance method and the Idirectsound8::initialize method instead of using the DirectSoundCreate8 function
Code
LPDIRECTSOUND8 lpds;
hr = CoCreateInstance(&CLSID_DirectSound8,
NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectSound8,
(LPVOID*) &lpds);
if (FAILED(hr))
{
ErrorHandler(hr); // Add error-handling here.
}
Clsid_directsound8 is the class identifier of the DirectSound driver object class, Iid_idirectsound8 is the interface identifier. The LPDS parameter receives a pointer to this interface.