繁体   English   中英

LoadLibrary('user32.dll')返回14007

[英]LoadLibrary('user32.dll') returns 14007

如果我尝试使用LoadLibrary加载User32.dll,该函数将返回错误14007(ERROR_SXS_KEY_NOT_FOUND)。 这是我使用的代码:

SetLastError(0); //To make sure there are no previous errors.
HINSTANCE hUserModule = LoadLibrary(L"User32.dll");
if (hUserModule == NULL) { //Checking if hUserModule is NULL
    MessageBoxA(NULL, "Fatal error", "", 16);
    ExitProcess(0);
} //hUserModule is not NULL
printf("%d\n", GetLastError()); //14007
DWORD paMessageBoxA = (DWORD)GetProcAddress(hUserModule, "MessageBoxA");
__MessageBoxA MsgBox = (__MessageBoxA)paMessageBoxA; //typedef int(__stdcall *__MessageBoxA)(HWND, LPCSTR, LPCSTR, UINT);
MsgBox(NULL, "", "", 64); //Application crahses

因此,hUserModule不是NULL,但也是无效的。 为什么是这样?

编辑:GetModuleHandle也不起作用

在64位系统上,地址为64位宽。 DWORD类型为“ 32位无符号整数”(从此MSDN类型参考引用 )。

这意味着您将截断GetProcAddress收到的地址,使其无效。

解决方案是使用适当的指针类型,将其转换为该类型而不是DWORD 也许像

__MessageBoxA MsgBox = (__MessageBoxA) GetProcAddress(hUserModule, "MessageBoxA");

(假定__MessageBoxA 正确的指针。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM