Using a Callback Function to Manage Buffered Playback

You can define your own callback function to manage buffered playback of MIDI output devices. The callback function is documented as MidiOutProc.

The following messages can be sent to the wMsg parameter of the MidiOutProc callback function.

MOM_CLOSE Sent when the device is closed by using the midiOutClose function.
MOM_DONE Sent when the device driver is finished with a data block sent by using the midiOutLongMsg or midiStreamOut function.
MOM_OPEN Sent when the device is opened by using the midiOutOpen function.

These messages are similar to those sent to window procedure functions, but the parameters are different. A handle of the open MIDI device is passed as a parameter to the callback function, along with the doubleword of instance data passed by using midiOutOpen.

After the driver is finished with a data block, you can clean up and free the data block. Because of the suggested restrictions on callback functions, it is better not to do this from within the callback function.