Windows 7 dsound.dll load from dll crash

Posted by Jonas Byström on Stack Overflow See other posts from Stack Overflow or by Jonas Byström
Published on 2010-04-28T13:06:06Z Indexed on 2010/04/28 13:23 UTC
Read the original article Hit count: 309

Filed under:
|
|
|
|

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!?! :)

© Stack Overflow or respective owner

Related posts about windows-7

Related posts about dsound