From 0a45d4de0cf24451f8acb3d120a0aced655aa046 Mon Sep 17 00:00:00 2001 From: David Holland Date: Wed, 18 Jun 2025 20:25:09 +1000 Subject: [PATCH] Fix `WAVEFORMATEX` struct size (#5356) * fix WAVEFORMATEX struct size * fix size test for WAVEFORMATEX * pack WAVEFORMATEXTENSIBLE --- core/sys/windows/winmm.odin | 4 ++-- tests/core/sys/windows/test_windows_generated.odin | 4 +++- tests/core/sys/windows/win32gen/win32gen.cpp | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/sys/windows/winmm.odin b/core/sys/windows/winmm.odin index 204ab99c8..b85548b85 100644 --- a/core/sys/windows/winmm.odin +++ b/core/sys/windows/winmm.odin @@ -589,7 +589,7 @@ WAVE_FORMAT_FLAC :: 0xF1AC /* flac.sourceforge.net */ WAVE_FORMAT_EXTENSIBLE :: 0xFFFE /* Microsoft */ -WAVEFORMATEX :: struct { +WAVEFORMATEX :: struct #packed { wFormatTag: WORD, nChannels: WORD, nSamplesPerSec: DWORD, @@ -603,7 +603,7 @@ LPCWAVEFORMATEX :: ^WAVEFORMATEX // New wave format development should be based on the WAVEFORMATEXTENSIBLE structure. // WAVEFORMATEXTENSIBLE allows you to avoid having to register a new format tag with Microsoft. // Simply define a new GUID value for the WAVEFORMATEXTENSIBLE.SubFormat field and use WAVE_FORMAT_EXTENSIBLE in the WAVEFORMATEXTENSIBLE.Format.wFormatTag field. -WAVEFORMATEXTENSIBLE :: struct { +WAVEFORMATEXTENSIBLE :: struct #packed { using Format: WAVEFORMATEX, Samples: struct #raw_union { wValidBitsPerSample: WORD, /* bits of precision */ diff --git a/tests/core/sys/windows/test_windows_generated.odin b/tests/core/sys/windows/test_windows_generated.odin index 3d8184a8b..c9c7f6729 100644 --- a/tests/core/sys/windows/test_windows_generated.odin +++ b/tests/core/sys/windows/test_windows_generated.odin @@ -527,8 +527,10 @@ verify_winmm :: proc(t: ^testing.T) { // mmsyscom.h expect_size(t, win32.MMVERSION, 4) expect_size(t, win32.MMTIME, 12) + // mmreg.h + expect_size(t, win32.WAVEFORMATEX, 18) + expect_size(t, win32.WAVEFORMATEXTENSIBLE, 40) // mmeapi.h - expect_size(t, win32.WAVEFORMATEX, 20) expect_size(t, win32.WAVEHDR, 48) expect_size(t, win32.WAVEINCAPSW, 80) expect_size(t, win32.WAVEOUTCAPSW, 84) diff --git a/tests/core/sys/windows/win32gen/win32gen.cpp b/tests/core/sys/windows/win32gen/win32gen.cpp index 57a094cd5..13b9c25d4 100644 --- a/tests/core/sys/windows/win32gen/win32gen.cpp +++ b/tests/core/sys/windows/win32gen/win32gen.cpp @@ -1,6 +1,7 @@ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include #include +#include #include #include #include @@ -702,8 +703,10 @@ static void verify_winmm(ofstream& out) { test_proc_comment("mmsyscom.h"); expect_size(MMVERSION); expect_size(MMTIME); - test_proc_comment("mmeapi.h"); + test_proc_comment("mmreg.h"); expect_size(WAVEFORMATEX); + expect_size(WAVEFORMATEXTENSIBLE); + test_proc_comment("mmeapi.h"); expect_size(WAVEHDR); expect_size(WAVEINCAPSW); expect_size(WAVEOUTCAPSW);