c++ - WinAPI 函数 LoadLibrary() 导致函数在执行错误期间失败

标签 c++ windows winapi visual-c++ dll

以下代码使用 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++ 十加仑头 请帮我解决这个问题。

最佳答案

documentation说:

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, call GetLastError.

当函数成功时,返回值不是NULL。这是你的场景。该文档未 promise 在函数成功时 GetLastError 将返回什么。某些 Win32 API 函数会在返回前调用 SetLastError(ERROR_SUCCESS),但不是全部。这是一个没有。

也就是说,没有错误。函数返回值表示成功,您不应该调用 GetLastError,因为它返回的值没有意义。

关于c++ - WinAPI 函数 LoadLibrary() 导致函数在执行错误期间失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47388091/

相关文章:

c++ - 引用对象的 STL 容器

c++ - 从两个绝对路径获取相对路径

c++ - 循环通过 std::vector 从 std::string 数组中查找匹配项,更简单的方法吗?

c++ - 如何使用 WinCrypt 和 C++ 以 PEM 格式导入私钥?

c++ - GetMessage() 会在主消息循环中返回 -1 吗?

c++ - 来自 cython wiki 的 Hello World 不起作用

c++ - 为 tolower 禁用不需要的过载

c++ - 在 Visual Studio 中将单精度浮点与 FFTW 结合使用

c++ - 如何在win32的窗口类中设置动态菜单?

visual-studio - 未解析的外部符号 _pathCombineW()