An application must be able to determine when a device driver is finished with the data block so that the application can unprepare and free the memory associated with the data block and header structure. The following list describes several ways to determine when a device driver is finished with a data block:
Messages sent to a callback function are similar to messages sent to a window, except that they have two DWORD parameters instead of one UINT and one DWORD parameter.
The following list describes techniques for passing instance data from an application to a callback function:
Note If you need more than 32 bits of instance data, pass a pointer to a structure containing the additional data.
This action creates a non-signaled event.
This call should be inside a loop that checks whether the WHDR_DONE bit is set in the dwFlags member of the WAVEHDR structure.
Because event callbacks do not receive specific close, done, or open notifications, an application might have to check the status of the process waiting for after the event occurs. It is possible for a number of tasks to be completed by the time WaitForSingleObject returns.
Note Messages sent to the window or thread callback are specific to the audio I/O device type used.
In addition to using a callback function, you can poll the dwFlags member of a WAVEHDR structure to determine when an audio I/O device is finished with a data block. Sometimes it is better to poll dwFlags than to wait for another mechanism to receive messages from the drivers. For example, after calling the waveOutReset or waveInReset function to release pending data blocks, you can immediately poll dwFlags for WHDR_DONE to be sure that the data blocks have been released.
Once you determine that the function has released the data block, call the waveInUnprepareHeader or waveOutUnprepareHeader function to unprepare the header file. After you have unprepared the header file, you can deallocate the memory normally.