This works fine on MacOS and it works fine in Reaper on Windows. However, in Ableton Live on Windows, the setMidiInputDeviceEnabled() fails. I tracked it down to a problem in MidiInput::openDevice(). This line generates a runtime exception in Live:
It seems to be a problem with the Win32 MidiInOpen call when the device has already been opened in the host. Apparently in that situation a plugin cannot open that same device. Since the WinRT option in Cubase doesn’t have this problem, I’m guessing this limitation has been fixed in WinRT MIDI.
Yes, it’s not really a JUCE issue, but trying to connect to a midi device from a plugin on Windows is a pain. Probably the best strategy is to advise the user to take steps to make sure the host does not open a connection to the device, thus freeing it up for the plugin. It wouldn’t be easy to catch the error and display a meaningful error message since the way to workaround this would be different for every DAW.