Opening MIDI Input Devices

Use the midiInOpen function to open a MIDI input device for recording. 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 midiInOpen is as follows:

WORD midiInOpen(lphMidiIn, wDeviceID, dwCallback, dwInstance, dwFlags)

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

The wDeviceID parameter is a WORD that identifies the MIDI input device to be opened. See “Getting the Number of Devices,” earlier in this chapter, for details on device IDs.

The dwCallback parameter is a DWORD and specifies either a window handle or the address of a low-level callback function. You must specify the appropriate flag in the dwFlags parameter to indicate which type of callback you want.

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. You must specify either the CALLBACK_WINDOW or the CALLBACK_FUNCTION flag to indicate the type of callback you are using.