【发布时间】:2021-04-27 21:47:55
【问题描述】:
我正在将 Python 程序移植到 C++(在 Windows 上)。由于所述代码依赖于 DLL,因此我需要加载 DLL。但是,当我调用 LoadLibraryA 指定我的 DLL 的完整路径(带有反斜杠)时,它无法加载并且 GetLastError 返回 193。
这是一个示例程序来演示:
#include <iostream>
#include <windows.h>
using std::cout, std::endl;
int main(int argc, char* argv[]) {
if (argc != 2) {
cout << "You only need to specify one argument, path to DLL." << endl;
exit(2);
}
HMODULE dll = LoadLibraryA(argv[1]);
if (dll == NULL) {
cout << "DLL at " << argv[1] << " could not be loaded." << endl;
}
FreeLibrary(dll);
return 0;
}
我将我的 DLL 的完整路径(如“C:\path\to\somewhere\test.dll”)指定为第一个命令行参数,但它失败了。为什么它不会加载,即使它在 JNA 和 ctypes 等外部函数接口中加载?
编辑 1:DLL 是 64 位的。
【问题讨论】:
-
混合 32 位和 64 位?
-
你的 dll 和可执行文件是为相同的架构构建的吗?
-
Error 193 是
ERROR_BAD_EXE_FORMAT,“%1 不是有效的 Win32 应用程序。”