Using an Event Callback to Process Driver Messages
[The feature associated with this page, Waveform Audio, is a legacy feature. It has been superseded by WASAPI and Audio Graphs. WASAPI and Audio Graphs have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use WASAPI and Audio Graphs instead of Waveform Audio, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
To use an event callback, use the CreateEvent function to create a manual-reset event. In the call to the waveOutOpen function, specify CALLBACK_EVENT for the fdwOpen parameter. After you call the waveOutPrepareHeader function, but before sending waveform-audio data to the device, put the event into a nonsignaled state by calling the ResetEvent function. Then, inside a loop that checks whether the WHDR_DONE flag is set in the dwFlags member of the WAVEHDR structure, call the WaitForSingleObject function, specifying as parameters the event handle and a time-out value.
Because event callbacks do not receive specific close, done, or open notifications, an application might have to check the status of the process it is waiting for after the event occurs. It is possible that a number of tasks could have been completed by the time WaitForSingleObject returns.
Related topics