MMRESULT midiInOpen(lphMidiIn, wDeviceID, dwCallback, dwCallbackInstance, dwFlags) | |||
LPHMIDIIN lphMidiIn; | |||
UINT wDeviceID; | |||
DWORD dwCallback; | |||
DWORD dwCallbackInstance; | |||
DWORD dwFlags; |
The midiInOpen function opens a specified MIDI input device.
lphMidiIn
Specifies a far pointer to an HMIDIIN handle. This location is filled with a handle identifying the opened MIDI input device. Use the handle to identify the device when calling other MIDI input functions.
wDeviceID
Identifies the MIDI input device to be opened.
dwCallback
Specifies the address of a fixed callback function or a handle to a window called with information about incoming MIDI messages.
dwCallbackInstance
Specifies user instance data passed to the callback function. This parameter is not used with window callbacks.
dwFlags
Specifies a callback flag for opening the device. This parameter may have one of the following values:
Value | Meaning |
CALLBACK_WINDOW | ||
dwCallback is assumed to be a window handle. | ||
CALLBACK_FUNCTION | ||
dwCallback is assumed to be a callback procedure address. |
Returns zero if the function was successful. Otherwise, it returns an error number. Possible error returns are:
Value | Meaning |
MMSYSERR_BADDEVICEID | Specified device ID is out of range. |
MMSYSERR_ALLOCATED | Specified resource is already allocated. |
MMSYSERR_NOMEM | Unable to allocate or lock memory. |
Use midiInGetNumDevs to determine the number of MIDI input devices present in the system. The device ID specified by wDeviceID varies from zero to one less than the number of devices present. The MIDI_MAPPER constant may also be used as a device id.
If a window is chosen to receive callback information, the following messages are sent to the window procedure function to indicate the progress of MIDI input: MM_MIM_OPEN, MM_MIM_CLOSE,MM_MIM_DATA, MM_MIM_LONGDATA, MM_MIM_ERROR,MM_MIM_LONGERROR.
If a function is chosen to receive callback information, the following messages are sent to the function to indicate the progress of MIDI input: MIM_OPEN, MIM_CLOSE, MIM_DATA, MIM_LONGDATA,MIM_ERROR, MIM_LONGERROR. 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.
void CALLBACK MidiInFunc(hMidiIn, wMsg, dwInstance,
dwParam1, dwParam2)
HMIDIIN hMidiIn;
UINT wMsg;
DWORD dwInstance;
DWORD dwParam1;
DWORD dwParam2;
MidiInFunc 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.
hMidiIn
Specifies a handle to the MIDI input device.
wMsg
Specifies a MIDI input message.
dwInstance
Specifies the instance data supplied with midiInOpen.
dwParam1
Specifies a parameter for the message.
dwParam2
Specifies a parameter for the message.
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.
midiInClose