http://bugs.winehq.org/show_bug.cgi?id=28413
--- Comment #19 from Jörg Höhle hoehle@users.sourceforge.net 2011-11-22 04:19:42 CST --- My tests on an older system showed that - CreateWindow handles feature this 16bit counter (more precisely, it looks like every 16 low bits handle has its own 16 high bits counter). - HMIDIOUT handles don't.
Your test shows that HWAVEOUT doesn't either. Indeed, R. Chen talks about window handles in the blog entry. Although it would be good to add this protection to winmm handles, it's possible that AJ objects based on the "100% bug compatible" argument.
Your patch looks good, except the one junk bit is not checked anymore to detect bogus handles.