以下代码使用 LoadLibrary() 在运行时加载一个 dll。
boolean Load_Internals_dll()
{
boolean result = true;
//LOG_INIT;
HINSTANCE hApexRLIO = LoadLibrary(L"APEX_RLIO_Internals.dll");
printf("Checking getlasterror after loadlibrary:\n",GetLastError());
if(NULL == hApexRLIO)
{
result = false;
printf("[ERR]: Unable to load dll\n");
LOG_PRINT(" [ERR]: Unable to load dll.\n" );
}
result = InitRSIDComm_Lib_Func();
//LOG_EXIT;
return result;
}
加载dll后,发现句柄hApexRLIO不为空,但函数GetLastError()返回系统错误码1627(Function failed during execution)。
此错误的可能原因是什么?
网上关于这个错误代码的文档不多, VC++ 十加仑头 请帮我解决这个问题。
最佳答案
If the function succeeds, the return value is a handle to the module.
If the function fails, the return value is
NULL
. To get extended error information, callGetLastError
.
当函数成功时,返回值不是NULL
。这是你的场景。该文档未 promise 在函数成功时 GetLastError
将返回什么。某些 Win32 API 函数会在返回前调用 SetLastError(ERROR_SUCCESS)
,但不是全部。这是一个没有。
也就是说,没有错误。函数返回值表示成功,您不应该调用 GetLastError
,因为它返回的值没有意义。
关于c++ - WinAPI 函数 LoadLibrary() 导致函数在执行错误期间失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47388091/