As the final initialization step in the InitDSoundCapture function, you will set up notification positions in the capture buffer so that the application knows when it's time to stream more data to the file. In the example, these positions are set at the beginning and halfway mark of the buffer.
First you create the required number of events and store their handles in the rghEvent array:
for (int i = 0; i < NUMCAPTUREEVENTS; i++)
{
rghEvent[i] = CreateEvent(NULL, FALSE, FALSE, NULL);
if (NULL == rghEvent[i]) return FALSE;
}
Next, you initialize the array of DSBPOSITIONNOTIFY structures, each of which associates a position in the buffer with an event handle:
rgdscbpn[0].dwOffset = 0;
rgdscbpn[0].hEventNotify = rghEvent[0];
rgdscbpn[1].dwOffset = dscbDesc.dwBufferBytes/2;
rgdscbpn[1].hEventNotify = rghEvent[1];
Finally, you get the IDirectSoundNotify interface from the capture buffer and pass the DSBPOSITIONNOTIFY array to the SetNotificationPositions method:
if FAILED(IDirectSoundCaptureBuffer_QueryInterface(lpdscb,
IID_IDirectSoundNotify, (VOID **)&lpdsNotify))
return FALSE;
if FAILED(IDirectSoundNotify_SetNotificationPositions(lpdsNotify,
NUMCAPTUREEVENTS, rgdscbpn))
{
IDirectSoundNotify_Release(lpdsNotify);
return FALSE;
}
return TRUE;
} // end InitDSoundCapture()
Note that if you need to set up notifications for both a capture buffer and a secondary (output) buffer, the event handles have to be stored in the same rghEvent array. When you receive the notifications in the message loop, you can distinguish between the two types of events by the index number.