1

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); 
    }
}
skm
  • 5,015
  • 8
  • 43
  • 104

2 Answers2

3

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.

Former contributor
  • 2,466
  • 2
  • 10
  • 15
  • Ok, I used the dependency walker any found out that the DLL is in x32 configuration and that's why did not load in my program. – skm Sep 17 '19 at 07:59
2

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.

Community
  • 1
  • 1
ypnos
  • 50,202
  • 14
  • 95
  • 141