I'm getting a crash when loading dsound.dll from another DLL in Windows 7. The following code crashes:
#include <Windows.h>
#include <mmreg.h>
#include <dsound.h>
#include <assert.h>
HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext);
HMODULE hDsound;
BOOL CALLBACK DSEnum(LPGUID a, LPCSTR b, LPCSTR c, LPVOID d)
{
return TRUE;
}
void CrashTest()
{
HRESULT hr;
hDsound = LoadLibraryA("dsound.dll");
assert(hDsound);
*(void**)&pDirectSoundEnumerateA = (void*)GetProcAddress(hDsound, "DirectSoundEnumerateA");
assert(pDirectSoundEnumerateA);
hr = pDirectSoundEnumerateA(DSEnum, NULL);
assert(!FAILED(hr));
}
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hModule);
CrashTest();
}
}
with this error code:
Unhandled exception at ... in ...: 0xC0000005: Access violation reading location 0x00000044.
(it's always 0x44 for some reason). It works on Windows XP or when loading directly from the .exe (not from a separate DLL). Help!?! :)