MIDI device application hangs when you use former MIDI API in Windows 10

This article helps you resolve the problem where MIDI device application hangs in Windows 10 when you use the legacy MIDI API.

Original product version:   Windows 10
Original KB number:   4460006

Symptoms

Consider the following scenario:

  • You develop an application for Windows 10 that controls external MIDI devices.
  • The application uses the former Microsoft Windows MIDI API to communicate with external devices.

In this situation, the application may hang. Additionally, you can't terminate the application by using Task Manager or any other method to exit the process. The only way to recover from this scenario is to restart the computer.

See the following example of a call stack from when the application hang occurs:

ntdll!NtWaitForSingleObject+0x14
KERNELBASE!WaitForSingleObjectEx+0x9f
wdmaud!CMIDIOutDevice::WriteEvent+0xa8
wdmaud!CMIDIOutDevice::PlaySysEx+0x6d
wdmaud!HwModMessage+0x11a
wdmaud!CDigitalAudio::Init+0x37ac
winmmbase!midiMessage+0xa6
winmmbase!midiOutLongMsg+0xbc
MidiAppDriver!CMidiController::WriteTextToLCD+0x1f1
MidiAppDriver!CMidiController::KeepAlive+0x12a
MidiAppDriver!TimerThread+0x46
kernel32!BaseThreadInitThunk+0x14
ntdll!RtlUserThreadStart+0x21

Cause

This issue may occur after a Plug and Play (PnP) removal event, because the former Microsoft Windows MIDI API implementation does not correctly handle that removal in Windows 10.

Resolution

To fix this issue, use the new Windows Runtime (WinRT) API functions to replace the former API.

Note

Important notes about WinRT API functions:

  • The API functions are primarily available to be called from a modern/UWP app.
  • Such modern APPs can be developed by using C++ language.
  • There's an option to develop classic user-mode desktop application that consumes WinRT APIs by using the DualApiPartitionAttribute attribute. For example, the MidiInPort Class lists it.

Status

Microsoft has confirmed that this is a problem in Windows 10.

References