midiOutPrepareHeader() issue on Win7

Hi All
My app works fine on Mac, but has problem on Win7 64bits. I'm using the latest Juce version, compiling on Win using vs2012 express.
I'm sending/receiving sysexs to/from a USB MIDI device attached.

Both Mac and Win work fine when my app runs, anyway, when I want to update the firmware of the attached USB MIDI keyboard, I send a Sysex to the device that makes it disconnecting/reconnecting with a different device name (it restarts in boot loader mode).

Once this sysex is sent, my app scans MIDI devices until it finds the new attached device (checking device name). This new device is found without problem, so I close the previous MIDI in and out, and reopen both with the new attached device, anyway, i'm no longer able to send Sysex to this new device.

It works perfectly on Mac, but on Win7, the midiOutPrepareHeader() in MidiOutput::sendMessageNow (const MidiMessage& message) returns something different than MMSYSERR_NOERROR. My sysex is not sent on Win, while it works fine on Mac.

I double checked the parameters passed to midiOutPrepareHeader() and everything seems ok to me.

I was wondering if closing Midi in & out when the new device is found, then reopen both with the new device is enough ? Is there a way to reset all MIDI in & out to be sure everything is flushed correctly before communicating with the new attached device ? I did not find any relevant function for this.
Thanks for any help.

Yes, dodgy drivers can be a pain..

To restart a device, just delete and re-create the object - that should certainly do the job.

Thanks for your prompt reply.
My MidiIn and Out are scoped pointers declared as follow:

ScopedPointer <MidiInput> midiInput;
ScopedPointer <MidiOutput> midiOutput;

Calling "delete midiInput;" crashes the app, sorry for this stupid question but I'm new to Juce ...
What is the proper way to delete those MIDI devices ?
Again, thanks


You'd better learn how smart pointers work! Setting the pointer = nullptr will delete the thing it currently points to. Never call 'delete' directly.

Fantastic !

Thank you so much Jules, everything works as expected now on Win !