Skip to content

Patch WinMM header structure#89

Merged
atsushieno merged 1 commit intoatsushieno:masterfrom
Nytra:winmmHeaderPatch
Feb 25, 2026
Merged

Patch WinMM header structure#89
atsushieno merged 1 commit intoatsushieno:masterfrom
Nytra:winmmHeaderPatch

Conversation

@Nytra
Copy link
Contributor

@Nytra Nytra commented Feb 25, 2026

Patched according to #88

I did not change the ints to uints because it would require more changes in other parts of the code.

This has not been tested.

@atsushieno atsushieno merged commit 332d1d7 into atsushieno:master Feb 25, 2026
1 check was pending
@atsushieno
Copy link
Owner

Thanks for the fix!

@Nytra Nytra deleted the winmmHeaderPatch branch February 25, 2026 17:58
Copy link

@Psychlist1972 Psychlist1972 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this with .NET 10. Granted, that is likely a different version than you are using, but I wanted to check this because it didn't look correct.

  1. Be sure to add Pack=1 otherwise you get the wrong structure size. I was getting a size of 120 on 64 bit compiles without this.
  2. The [] after IntPtr are required to get a proper size for the struct, at least in .NET 10. In .NET 10, you get an exception if you don't include this.

You should end up with a size of 112. No more, no less.

[StructLayout(LayoutKind.Sequential, Pack =1)]
struct MidiHdr
{
    public IntPtr Data;
    public int BufferLength; // should be uint
    public int BytesRecorded; // should be uint
    public IntPtr User;
    public int Flags;
    public IntPtr Next; // of MidiHdr
    public IntPtr Reserved;
    public int Offset; // should be uint
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
    private IntPtr[] reservedArray;
}

@Psychlist1972
Copy link

Just to also be clear, the structure was always incorrect, and could have resulted in app crashes. What changed is we're now validating the passed-in size in the WinMM call. :)

@Nytra
Copy link
Contributor Author

Nytra commented Feb 26, 2026

Thanks. This PR should fix it #90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants