MidiInput and handleIncomingMidiMessage Problem

I just want to read the Midi data from my Midi input Device, and I tried this code (snippet):

    std::unique_ptr<juce::MidiInput> device =  juce::MidiInput::openDevice(juce::MidiInput::getAvailableDevices()[0].identifier, this);
    if (device == nullptr) {
        OutputDebugString("NULL");
    }
    else {
        OutputDebugString(device.get()->getDeviceInfo().name.getCharPointer());

    }

I check if it’s null and it is not null.
But even if I call the start() function the handleIncomingMidiMessage will not be called.
What am I missing ? I also looked up the MidiDemo, but it didn’t really helped.
This project is a plugin and not standalone.
I also tried the AudioDeviceManager Class and it worked, but I just want to understand why this isn’t working with the start() function.

Why are you trying to open a MIDI input in a plugin project? That’s not really the intended way to deal with MIDI in a plugin, all the MIDI input and output should happen through the host with the MidiBuffer you get into your plugin’s processBlock method.

Anyway if you really think this is the way how you want to do things, your device variable should not be a local variable since it’s immediately destroyed at the end of the function where you do that. You should instead have the device as a member variable.

Thank you,
and then how can I manage the Midi Data with the PluginProcess Class and PluginEditor Class when I want the UI show up (like in the textEditor) Key Pressed: A3, Velocity: 100 Note On … ?
The MidiDemo in the DemoRunner doesn’t really show it.

This may help you out:

https://docs.juce.com/master/tutorial_plugin_examples.html#tutorial_plugin_examples_arpeggiator