waveOutWrite
waveOutWritemsdn原文说明ThewaveOutWritefunction sends a data block to the given waveform-audio output device.
MMRESULT waveOutWrite(
HWAVEOUT hwo,
LPWAVEHDR pwh,
UINT cbwh
);
Parameters
hwo
Handle to the waveform-audio output device.
pwh
Pointer to aWAVEHDRstructure containing information about the data block.
cbwh
Size, in bytes, of theWAVEHDRstructure.
Return Values
Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
Value
Description
MMSYSERR_INVALHANDLE
Specified device handle is invalid.
MMSYSERR_NODRIVER
No device driver is present.
MMSYSERR_NOMEM
Unable to allocate or lock memory.
WAVERR_UNPREPARED
The data block pointed to by thepwhparameter hasn't been prepared.
Remarks
When the buffer is finished, the WHDR_DONE bit is set in thedwFlagsmember of theWAVEHDRstructure.
The buffer must be prepared with thewaveOutPrepareHeaderfunction before it is passed towaveOutWrite. Unless the device is paused by calling thewaveOutPausefunction, playback begins when the first data block is sent to the device.
Requirements
Windows NT/2000/XP:Included in Windows NT 3.1 and later.
Windows 95/98/Me:Included in Windows 95 and later.
Header:Declared in Mmsystem.h; include Windows.h.
Library:Use Winmm.lib.
See Also
Waveform Audio, Waveform Functions,WAVEHDR,waveOutPrepareHeader,waveOutPause中文说明:警告:在使用此函数之前,请先调用waveOutPrepareHeader函数
这个函数将在音频媒体中播放pwh指定的数据
hwo 音频设备句柄,通过waveOutOpen获得
pwh 播放数据的信息.
注意:要播放的数据一般在声音文件里面获得,并填入这个结构.由于是直接播放数据,所以要播放多少数据可以通过修改这个结构来达到目的.
cbwh pwh结构的大小,单位字节/BYTE
返回值
MMSYSERR_NOERROR 成功
MMSYSERR_INVALHANDLE hwo是无效的
MMSYSERR_NODRIVER 没有音频设备
MMSYSERR_NOMEM 内存不足
WAVERR_UNPREPARED 没有调用waveOutPrepareHeader函数,或者调用waveOutPrepareHeader失败
注意
播放完数据后 WHDR_DONE 会设置到pwh指向的结构体中的dwFlags成员
在调用本函数之前必须调用waveOutPrepareHeader函数.
除非是恢复被waveOutPause函数暂停的设备,回调函数会在第一个数据块一送达设备的时候就开始运作.回调函数在waveOutOpen里面设置
警告:请不要在回调函数里面调用任何的waveOut系列的函数,否则一定会造成死锁(也就是程序失去响应).哪怕是waveOutUnprepareHeader,waveOutClose
也是不行的.我看到网上有些例子在回调函数里面使用了这个,这是错误的做法.
要求:
系统要求:NT3.1以及之后的版本,windows95以及之后的版本.(其实就是没有什么系统要求,只要是windows就好)
头文件:本系列函数声明在Mmsystem.h中.包含Windows.h就可以了.
库文件:Winmm.lib个人使用心得首先是头文件,库要包含到项目里面去,这我就不废话了
调用顺序是waveOutOpen -> waveOutPrepareHeader ->waveOutWrite
然后是waveOutUnprepareHeader,这个调用的时机必须是在播放完成以后.也就是那个WHDR_DONE设置到dwFlags之后.没有播放完成调用这个会导致一个异常中断.访问的地方是不可读的.
最后关闭时调用waveOutClose.调用完这个后,hwo就是一个不可靠的变量了.不能再使用这个来传给其他waveOut函数了