简体   繁体   中英

QLibrary is not loading DLL

I want to load DLL in a C++ program and create function pointers. To avoid any confusion, I am providing the absolute path of the DLL. But still, the DLL is not loaded.

My Code:

void CallFunctionPointers()
{
    QString strMsg;
    QString strLibPath("D:\\dll\\AtmoRemote.dll");

    QLibrary* m_p_lib = new QLibrary();
    m_p_lib->setFileName(strLibPath);

    if (!m_p_lib->load())
    {
        strMsg = QString("Could not load %1").arg(strLibPath); //<<<<-----------PROGRAM ALWAYS ENTERS HERE
    }
    else
    {
        strMsg = QString("Successfully loaded: %1").arg(strLibPath); 
    }
}

There may be many reasons, impossible to diagnose with the details provided here.

For instance: the process using Qt is 64 bits and the DLL is 32 bits. Or vice-versa. Another one: the DLL depends on other DLLs not available by QLibrary. My suggestion for you: use dependency walker or a similar utility to diagnose these issues.

Check for the error.

QString QLibrary::errorString() const

Returns a text string with the description of the last error that occurred. Currently, errorString will only be set if load(), unload() or resolve() for some reason fails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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