1
如果我尝试使用LoadLibrary加载User32.dll中的函数返回错误14007(ERROR_SXS_KEY_NOT_FOUND)。这是我使用的代码:调用LoadLibrary( 'user32.dll中')返回14007
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也不起作用
一般来说,你应该检查错误代码(由'GetLastError'返回)*仅*如果一个函数失败。否则,你可能会得到误报。 –
至于你的崩溃,你是否检查'GetProcAddress'没有失败? –
最后,与您的问题完全无关,但没有以双下划线开头的自己的符号。这些由所有范围内的“实现”(编译器和标准库)保留。 [见这个老问题及其答案]以获取更多信息(http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)。 –