waveOutOpen

Syntax

WORD waveOutOpen(lphWaveOut, wDeviceID, lpFormat, dwCallback, dwCallbackInstance, dwFlags)

This function opens a specified waveform output device for playback.

Parameters

LPHWAVEOUT 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.

WORD wDeviceID

Identifies the waveform output device to open. Use a valid device ID or the following flag:

WAVE_MAPPER

If this flag is specified, the function selects a waveform output device capable of playing the given format.

LPWAVEFORMAT lpFormat

Specifies a pointer to a WAVEFORMAT structure that identifies the format of the waveform data to be sent to the waveform output device.

DWORD 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.

DWORD dwCallbackInstance

Specifies user instance data passed to the callback. This parameter is not used with window callbacks.

DWORD dwFlags

Specifies flags for opening the device.

WAVE_FORMAT_QUERY

If this flag is specified, the device is be queried to determine if it supports the given format but is not actually opened.

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.

Return Value

Returns zero if the function was successful. Otherwise, it returns an error number. Possible error returns are:

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.

Comments

Use waveOutGetNumDevs to determine the number of waveform output devices present in the system. The device ID specified by wDeviceID varies from zero to one less than the number of devices present.

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, 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, 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.

Callback

void FAR PASCAL WaveOutFunc(hWaveOut, wMsg, dwInstance, dwParam1, 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.

Parameters

HWAVEOUT hWaveOut

Specifies a handle to the waveform device associated with the callback.

WORD wMsg

Specifies a waveform output message.

DWORD dwInstance

Specifies the user instance data specified with waveOutOpen.

DWORD dwParam1

Specifies a parameter for the message.

DWORD dwParam2

Specifies a parameter for the message.

Comments

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.

See Also

waveOutClose