Windows 7 dsound.dll 从 dll 崩溃加载
我在 Windows 7 中从另一个 DLL 加载 dsound.dll 时发生崩溃。以下代码崩溃:
#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();
}
}
出现此错误代码:(
Unhandled exception at ... in ...: 0xC0000005: Access violation reading location 0x00000044.
由于某种原因,它始终为 0x44)。它适用于 Windows XP 或直接从 .exe(而不是从单独的 DLL)加载时。帮助!?! :)
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!?! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对不应该从
DllMain
调用LoadLibrary
。来自文档:相反,您可以创建并导出初始化函数并在加载 DLL 后调用它。
You should never call
LoadLibrary
fromDllMain
. From the documentation:Instead, you can create and export an initialization function and call it after loading the DLL.