private void UnprepareHeader(bool input, IntPtr handle, IntPtr headerPtr) { if (headerPtr == IntPtr.Zero) { return; } MIDIHDR midihdr = null; try { midihdr = (MIDIHDR)Marshal.PtrToStructure(headerPtr, typeof(MIDIHDR)); } catch { } if (midihdr != null) { try { if (input) { Midi.MIDI_InUnprepareHeader(handle, headerPtr); } else { Midi.MIDI_OutUnprepareHeader(handle, headerPtr); } } catch { } try { if (midihdr.data != IntPtr.Zero) { Marshal.FreeHGlobal(midihdr.data); } } catch { } try { Marshal.FreeHGlobal(headerPtr); } catch { } } }