PDA

View Full Version : LNK1107: Invalid or damaged file: reading at 0x2E0 not possible



tim5
1st April 2021, 22:55
Hello,

I only have a .DLL file from an external source. No .lib or .h. This is why I am using LoadLibrary (QLibrary)- I was reading that if I only have the .dll I have to do it like that.

I know the functions but dont know how to implement the Dll correctly.

This ist what I tried:

.pro


QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++14

LIBS += "C:\Users\lauer\Qt_Projects\build-firsttry32bit_gebiom-Desktop_x86_windows_msvc2019_pe_32bit-Debug\debug\GP_MUX_MODAWIFI.dll."


SOURCES += \
main.cpp \
mainwindow.cpp

HEADERS += \
mainwindow.h

FORMS += \
mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target





main.cpp


#include "mainwindow.h"

#include <QApplication>
#include <QLibrary>
#include <QDebug>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

if (QLibrary::isLibrary("C:/Users/lauer/Qt_Projects/build-firsttry32bit_gebiom-Desktop_x86_windows_msvc2019_pe_32bit-Debug/debug/GP_MUX_MODAWIFI.dll")) { // GP_MUX_MODAWIFI.dll
QLibrary lib("C:/Users/lauer/Qt_Projects/build-firsttry32bit_gebiom-Desktop_x86_windows_msvc2019_pe_32bit-Debug/debug/GP_MUX_MODAWIFI.dll");
lib.load();
if (!lib.isLoaded()) {
qDebug() << lib.errorString();
}

if (lib.isLoaded()) {
qDebug() << "success";

// Resolves symbol to
// void the_function_name()
typedef int (*FunctionPrototype)();
auto function1 = (FunctionPrototype)lib.resolve("MUX_Version");


// if null means the symbol was not loaded
if (function1) function1();
}
}

MainWindow w;
w.show();
return a.exec();
}





What can I do?
What am I doing wrong?

I already looked into several forum entries but did not find the working answer.

Thanks in advance
Tim

d_stranz
2nd April 2021, 16:49
Please do not double post. You already have one thread going on this issue. Make your additional comments there.

Line 7 of your .pro file: You cannot link to a DLL, you can only link to static libraries or export libraries created for a DLL. (.lib files).