I've found the problem. It was in our own code
mmRes = waveInOpen(&m_hwi, m_nDeviceID, &wfx, (DWORD)waveInProc, (DWORD)this,
CALLBACK_FUNCTION);
Here 4th and 5th parameters were expected as DWORD_PTR but here they were being cast to DWORD. Since sizeof(DWORD) is 4 and sizeof(DWORD_PTR) is 8 on an 64 bit architecture this led to truncation and hence the crash.
So the correct code is:
mmRes = waveInOpen(&m_hwi, m_nDeviceID, &wfx, (DWORD_PTR)waveInProc, (DWORD_PTR)this,
CALLBACK_FUNCTION);