MMRESULT waveOutOpen(lphWaveOut, uDeviceID, lpFormat, dwCallback, dwCallbackInstance, dwFlags) | |||
LPHWAVEOUT lphWaveOut; | |||
UINT uDeviceID; | |||
LPWAVEFORMAT lpFormat; | |||
DWORD dwCallback; | |||
DWORD dwCallbackInstance; | |||
DWORD dwFlags; |
The waveOutOpen function opens a specified waveform output device for playback.
lphWaveOut
Specifies a far pointer to an HWAVEOUT handle. This location is filled with a handle identifying the opened waveform output device. Use the handle to identify the device when calling other waveform output functions. This parameter may be NULL if the WAVE_FORMAT_QUERY flag is specified for dwFlags.
uDeviceID
Identifies the waveform output device to open. Use a valid device ID or the WAVE_MAPPER flag.
If this flag is specified, the function selects a waveform output device capable of playing the given format.
lpFormat
Specifies a pointer to a WAVEFORMAT structure that identifies the format of the waveform data to be sent to the waveform output device.
dwCallback
Specifies the address of a callback function or a handle to a window called during waveform playback to process messages related to the progress of the playback. Specify NULL for this parameter if no callback is desired.
dwCallbackInstance
Specifies user instance data passed to the callback. This parameter is not used with window callbacks.
dwFlags
Specifies flags for opening the device.
Value | Meaning |
WAVE_FORMAT_QUERY | ||
If this flag is specified, the device is queried to determine if it supports the given format but is not actually opened. | ||
WAVE_ALLOWSYNC | ||
If this flag is not specified, then the device will fail to open if it is a synchronous device. | ||
CALLBACK_WINDOW | ||
If this flag is specified, dwCallback is assumed to be a window handle. | ||
CALLBACK_FUNCTION | ||
If this flag is specified, dwCallback is assumed to be a callback procedure address. |
Returns zero if the function was successful. Otherwise, it returns an error number. Possible error returns are:
Value | Meaning |
MMSYSERR_BADDEVICEID | Specified device ID is out of range. |
MMSYSERR_ALLOCATED | Specified resource is already allocated. |
MMSYSERR_NOMEM | Unable to allocate or lock memory. |
WAVERR_BADFORMAT | Attempted to open with an unsupported wave format. |
Use waveOutGetNumDevs to determine the number of waveform output devices present in the system. The device ID specified by uDeviceID varies from zero to one less than the number of devices present. The WAVE_MAPPER constant may also be used as a device id.
The WAVEFORMAT structure pointed to by lpFormat may be extended to include type-specific information for certain data formats. For example, for PCM data, an extra WORD is added to specify the number of bits per sample. Use the PCMWAVEFORMAT structure in this case.
If a window is chosen to receive callback information, the following messages are sent to the window procedure function to indicate the progress of waveform output: MM_WOM_OPEN, MM_WOM_CLOSE, and MM_WOM_DONE
If a function is chosen to receive callback information, the following messages are sent to the function to indicate the progress of waveform output: WOM_OPEN, WOM_CLOSE, and WOM_DONE. The callback function must reside in a DLL. You do not have to use MakeProcInstance to get a procedure-instance address for the callback function.
void CALLBACK WaveOutFunc(hWaveOut, wMsg, dwInstance,
dwParam1, dwParam2)
HWAVEOUT hWaveOut;
UINT wMsg;
DWORD dwInstance;
DWORD dwParam1;
DWORD dwParam2;
WaveOutFunc is a placeholder for the application-supplied function name. The actual name must be exported by including it in an EXPORTS statement in the DLL's module-definition file.
hWaveOut
Specifies a handle to the waveform device associated with the callback.
wMsg
Specifies a waveform output message.
dwInstance
Specifies the user instance data specified with waveOutOpen.
dwParam1
Specifies a parameter for the message.
dwParam2
Specifies a parameter for the message.
Because the callback is accessed at interrupt time, it must reside in a DLL and its code segment must be specified as FIXED in the module-definition file for the DLL. Any data that the callback accesses must be in a FIXED data segment as well. The callback may not make any system calls except for PostMessage, timeGetSystemTime,timeGetTime, timeSetEvent, timeKillEvent, midiOutShortMsg, midiOutLongMsg, and OutputDebugStr.
waveOutClose