80.5.3 Opening MIDI Output Devices

Use the midiOutOpen function to open a MIDI output device for playback. This function opens the device associated with the specified device ID and returns a handle to the open device by writing the handle to a specified memory location. The syntax of midiOutOpen is as follows:

UINT midiOutOpen(lphMidiOut, wDeviceID, dwCallback, dwInstance, dwFlags)

The lphMidiOut parameter is an LPHMIDIOUT and specifies a far pointer to a memory location the function fills with a handle to the open MIDI output device. Use this handle to identify the MIDI device when calling other MIDI output functions.

The wDeviceID parameter is a UINT that identifies the MIDI output device to be opened. See “Querying Audio Devices,” earlier in this chapter, for details on device IDs.

The dwCallback parameter is a DWORD that specifies either a window handle or the address of a low-level callback function. The callback can be used to monitor the progress of the playback of MIDI system-exclusive data so the application can determine when to send additional data blocks, or when to free data blocks that have been sent. You must specify the appropriate flag in the dwFlags parameter to indicate which type of callback you want. If no callback is needed, this parameter is NULL.

The dwInstance parameter is a DWORD that specifies 32 bits of instance data sent to the callback function each time it is called.

The dwFlags parameter is a DWORD and specifies one or more flags for opening the MIDI device. If you are specifying a window or low-level callback in the dwCallback parameter, you must specify either the CALLBACK_WINDOW or the CALLBACK_FUNCTION flag to indicate the type of callback used.