MidiInput::openDevice() not working on Windows?

I’m trying to get input from a midi device to a VST3 plugin. I use this pattern:

deviceManager.setMidiInputDeviceEnabled (input.identifier, true);
deviceManager.addMidiInputDeviceCallback (input.identifier, this);

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:

    wrapper.reset (MidiService::getService().createInputWrapper (*in, deviceIdentifier, *callback));

In addition, this same problem occurs in Cubase if the WinRT MIDI option in Cubase is turned off.

Does anybody have experience getting JUCE MIDI input in VST3 to work on Windows?

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.

Unfortunate that its a run time exception.

Can you modify the plugin to give an alert about the MIDI status?

I assume the host retains full MIDI control, there is no way to make changes from the plugin, only request services?

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.