c - Windows 7 dsound.dll load from dll crash -


i'm getting crash when loading dsound.dll dll in windows 7. 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 error code:

unhandled exception @ ... in ...: 0xc0000005: access violation reading location 0x00000044. 

(it's 0x44 reason). works on windows xp or when loading directly .exe (not separate dll). help!?! :)

you should never call loadlibrary dllmain. documentation:

the entry-point function should perform simple initialization or termination tasks. must not call loadlibrary or loadlibraryex function (or function calls these functions), because may create dependency loops in dll load order. can result in dll being used before system has executed initialization code. similarly, entry-point function must not call freelibrary function (or function calls freelibrary) during process termination, because can result in dll being used after system has executed termination code.

instead, can create , export initialization function , call after loading dll.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -