keijiro / MidiJack

MIDI input plugin for Unity
697 stars 113 forks source link

MidiJackGetEndpointName() can return "unknown" for valid handles on 64-bit Windows #37

Open cdwfs opened 5 years ago

cdwfs commented 5 years ago

On 64-bit Windows, the ID returned by MidiJackGetEndpointIDAtIndex(index) is the low 32 bits of the DeviceHandle. When this ID is passed into MidiJackGetEndpointName(), it "converts" it back to a handle by casting it back to a 64-bit int, but the high 32 bits of the handle can not be recovered. Passing the resulting handle to midiInGetDevCaps() results in an invalid handle error, so the function returns "unknown".

The issue can be solved by maintaining a std::map<DeviceID, DeviceHandle> to convert 32-bit device IDs back to the full 64-bit device handle. I can prepare a PR if you'd like.