What's wrong with this code, part 16
This real-world problem shows up as an appcompat problem about every two or three weeks, so I figured I'd write it up as a "What's wrong with this code" snippet.
BOOL DllMain(HMODULE hModule, ULONG Reason, PCONTEXT pContext){ ghInst = (HINSTANCE) hModule; if (Reason == DLL_PROCESS_ATTACH) { DWORD cWaveDevices = 0; DisableThreadLibraryCalls(); cWaveDevices = waveOutGetNumDevs(); if ((cWaveDevices & 0xffff0000) != 0) { dprintf("Error retrieving wave device count\n"); } < Do some other initialization stuff > } else if (Reason == DLL_PROCESS_DETACH) { < Do some other initialization stuff > } return TRUE;}
This one's really simple, and should be blindingly obvious, but it's surprising the number of times people get it wrong.