Cannot load library *.dll Unknown error 0x000000c1

1

I try to call controller.dll from qt project using QLibrary but it returns such error. Cannot load library E:\"absolute path to the dll"\controller.dll: Unknown error 0x000000c1. What does that mean?

QLibrary lib;
lib.setFileName("E:\\absolute path to the dll\\controller.dll");
if(lib.load()) {
    qDebug()<<"Loaded";
} else {
    qDebug()<<"Not loaded";
    qDebug()<<lib.errorString();
}
c++
qt
dll
window
asked on Stack Overflow Apr 7, 2020 by karen.nik98

1 Answer

4

The error list you need is here. The symbolic name for that error is ERROR_BAD_EXE_FORMAT, and the error message is <filesoandso> is not a valid Win32 application. The DLL you're trying to open is either corrupt, or - most likely - it is for a different architecture. If you're compiling for 32 bits, use 32-bit DLLs. If you're compiling for 64 bits, use 64-bit DLLs.

You most likely have both a 32- and 64-bit compiler available on your system. If you use Qt Creator, it should be easy to switch - just select a different kit. There are no 64-bit kits displayed in the screenshot below, but you should have them if you've installed them when you installed Qt.

A screenshot from Qt Creator, displaying the Project pane in lower left corner of the application.

Why is the error called "bad EXE" and not "bad DLL"? Because on Windows both files have identical PE (Portable Executable) format, and it's only the presence of startup information inside the file that turns a PE file into an executable that can be started on its own. An EXE can do everything a DLL can, including exporting symbols :)

As an aside: use single forward slashes. Qt internally uses forward slashes for path delimiters. That way it can easily remain cross-platform. It translates them when it needs to interface with the OS.

answered on Stack Overflow Apr 7, 2020 by Kuba hasn't forgotten Monica • edited Apr 7, 2020 by Kuba hasn't forgotten Monica

User contributions licensed under CC BY-SA 3.0