public void SendBuffer(byte[] byteBuffer) { MidiInterop.MIDIHDR mIDIHDR = default(MidiInterop.MIDIHDR); mIDIHDR.lpData = Marshal.AllocHGlobal(byteBuffer.Length); Marshal.Copy(byteBuffer, 0, mIDIHDR.lpData, byteBuffer.Length); mIDIHDR.dwBufferLength = byteBuffer.Length; mIDIHDR.dwBytesRecorded = byteBuffer.Length; int uSize = Marshal.SizeOf(mIDIHDR); MidiInterop.midiOutPrepareHeader(this.hMidiOut, ref mIDIHDR, uSize); if (MidiInterop.midiOutLongMsg(this.hMidiOut, ref mIDIHDR, uSize) != MmResult.NoError) { MidiInterop.midiOutUnprepareHeader(this.hMidiOut, ref mIDIHDR, uSize); } Marshal.FreeHGlobal(mIDIHDR.lpData); }
public static extern MmResult midiInAddBuffer(IntPtr hMidiIn, [MarshalAs(UnmanagedType.Struct)] ref MidiInterop.MIDIHDR lpMidiInHdr, int uSize);
public static extern MmResult midiStreamOut(IntPtr hMidiStream, [MarshalAs(UnmanagedType.Struct)] ref MidiInterop.MIDIHDR pmh, int cbmh);
public static extern MmResult midiOutUnprepareHeader(IntPtr hMidiOut, [MarshalAs(UnmanagedType.Struct)] ref MidiInterop.MIDIHDR lpMidiOutHdr, int uSize);