On Thu, Dec 1, 2016 at 12:11 PM, Andrew Eikum aeikum@codeweavers.com wrote:
This seems like something you should be able to write a test for. I'm also curious how this manages to work on Windows >= XP
The test is at [1], if you run in Win9x it will fail (Win9x uses different thread), while running at >= XP it will succeed (>=XP uses same thread). This works in XP due to a shim that blindly ignores the SuspendThread/ResumeThread calls when inside a WinMM callback.
[1] http://source.winehq.org/source/dlls/winmm/tests/wave.c#0570
You need to be more careful about thread shutdown. See WINMM_StartDevicesThread and WINMM_DevicesThreadProc. I think you could use the same logic, including WINMM_DevicesThreadDone, to determine when to quit your new thread.
I tried understand what you say but I'm not sure yet. WINMM_DeleteWaveform is only called on process detach, can the DLL live after that? What you mean is that I should call
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR *)WINMM_StartDevicesThread, &g_9xthread_module);
inside WINMM_SetupCallback and then
FreeLibraryAndExitThread(g_9xthread_module, 1);
when returning from the thread?