Truncate MIDI SysEx messages after termination byte

Johannes Kroll jkroll at
Thu Jan 10 09:09:20 CST 2013

On Thu, 10 Jan 2013 12:04:02 +0100
Christian Costa <titan.costa at> wrote:

> In your code you stop checking F7 just before the last byte (until
> position lpMidiOutHdr->dwBufferLength-2);
> You can check the last byte as well. This is also valid and simplify the
> condition.
> The missing F7 byte case is handled by the for loop.

Ah, you mean that check. Yes, it's not strictly necessary, it just
decides whether it has to save & restore dwBufferSize or not.

> Regarding the single MMDRV_Message call, I was thinking about something
> like below.
> This also enable printing a WARN when F7 is missing which can be useful for
> debug.
>     DWORD oldBufferLength = lpMidiOutHdr->dwBufferLength;
>     DWORD ret;
>     for(i = 0; i < lpMidiOutHdr->dwBufferLength; i++)
>        /* SysEx messages are terminated by a 0xF7 byte. If the buffer
> contains additional
>           bytes, send only the bytes up to the termination byte. */
>         if((unsigned char)lpMidiOutHdr->lpData[i] == 0xF7)
>         {
>             lpMidiOutHdr->dwBufferLength = i+1;
>             break;
>         }
>     if (i == lpMidiOutHdr->dwBufferLength)
>         WARN("SysEx termination byte 0xF7 missing\n")
>     ret =  MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr,
> uSize);
>     /* restore the midi header to its original state. */
>     lpMidiOutHdr->dwBufferLength = oldBufferLength;
>     return ret;

I see nothing wrong with that apart from the broken formatting (please
don't use HTML mail). Did you test it?

I don't care which version is used, I would just be very happy if
*something* is included which makes my MIDI device work with Wine.

How does this generally work here, will there be feedback from a
maintainer on whether the patch will be included, or is it usually just
silently included?

Alexandre Julliard (or whoever decides this): Could you comment please?

And Christian, please, configure your mail client. The list mails I get
from you are directed to me, not the list, and they are missing the
List-Id field. 

More information about the wine-devel mailing list