midiInPrepareHeader function

The midiInPrepareHeader function prepares a buffer for MIDI input.


MMRESULT midiInPrepareHeader(
   HMIDIIN   hMidiIn,
   LPMIDIHDR lpMidiInHdr,
   UINT      cbMidiInHdr


  • hMidiIn
    Handle to the MIDI input device. To get the device handle, call midiInOpen.

  • lpMidiInHdr
    Pointer to a MIDIHDR structure that identifies the buffer to be prepared.

    Before calling the function, set the lpData, dwBufferLength, and dwFlags members of the MIDIHDR structure. The dwFlags member must be set to zero.

  • cbMidiInHdr
    Size, in bytes, of the MIDIHDR structure.

Return value

Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.

Return code Description

The specified device handle is invalid.


The specified address is invalid.


The system is unable to allocate or lock memory.



Before you pass a MIDI data block to a device driver, you must prepare the buffer by passing it to the midiInPrepareHeader function. After the header has been prepared, do not modify the buffer. After the driver is done using the buffer, call the midiInUnprepareHeader function.

The application can re-use the same buffer, or allocate multiple buffers and call midiInPrepareHeader for each buffer. If you re-use the same buffer, it is not necessary to prepare the buffer each time. You can call midiInPrepareHeader once at the beginning and then call midiInUnprepareHeader once at the end.

Preparing a header that has already been prepared has no effect, and the function returns zero.


Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]


Mmsystem.h (include Windows.h)





See also

Allocating and Preparing MIDI Data Blocks

MIDI Functions