QT无法使用QLibrary类加载动态链接库(.dll)

时间:2015-06-22 07:20:57

标签: qt visual-c++ dll qlibrary

我和我的朋友正在开展一个项目。

他给了我一个.dll文件,可以激活网络摄像头并流式传输视图。

他还给了我一个用VS2013 MFC编写的小例子项目来演示该功能。

typedef int(*ExtportFuncA)(void);
typedef int(*Open)(void);

void Ctrydll2Dlg::OnBnClickedOk()
{
    //CDialogEx::OnOK();
    ExtportFuncA  ga = NULL;
    HINSTANCE hLib = LoadLibrary(_T("ShowImg.dll"));
    if (hLib)
    {
        ga = (ExtportFuncA)GetProcAddress(hLib, "ExtportFuncA");
        ga();
    }
    system("pause");
}

void Ctrydll2Dlg::OnBnClickedButton1()
{
    Open  gb = NULL;
    HINSTANCE hLib = LoadLibrary(_T("ShowImg.dll"));
    if (hLib)
    {
        gb = (ExtportFuncA)GetProcAddress(hLib, "Open");
        int system = gb();
        if (system == -1)
        {
            printf("not get device");
        }
    }
}

但是,我无法在QT项目中加载该.dll文件。

#include <QCoreApplication>
#include <QLibrary>
#include <QDebug>
typedef int (*ExportFuncA)(void);

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QLibrary lib("ShowImg.dll");
    lib.load();
    if(!lib.load())
    {
        qDebug() << "Cannot Open Library";
        return 0;
    }
    ExportFuncA CLI = (ExportFuncA)lib.resolve("ExportFuncA");
    if(!CLI)
    {
        qDebug() << "Cannot Load Function";
        return 0;
    }
    printf("Hello World");
    return a.exec();
}

错误始终显示“无法打开库”,这意味着无法在开头加载.dll,

但是我朋友的演示项目在我的电脑上运行正常,我可以看到相机的图像。

我怀疑这个问题与32位和64位格式有关,

但由于我不熟悉.dll文件,任何建议都会感激不尽。

0 个答案:

没有答案
相关问题