【发布时间】:2017-11-11 08:29:47
【问题描述】:
我正在自定义项目中玩,并尝试在其他项目中创建一个 DLL 并使用LoadLibrary 函数在运行时链接,但它返回 126 错误。在谷歌上搜索了很多,但在大多数情况下,人们调试了其他人的程序。但我的 DLL 包含函数 string sayHello() { return "Hello"; }。应该应用哪些项目选项来让我成功加载这个 dll?并调用函数?谢谢
UDP:
vector<BYTE> decodedDll = base64_decode(base64dll);
string filename = string("lib.dll");
ofstream outfile(filename, ios::out | ios::binary);
outfile.write((const char*) &decodedDll[0], decodedDll.size());
outfile.close();
if (!fileExists(filename))
{
cout << "DLL file not found " << endl;
getchar();
return;
}
HINSTANCE hGetProcIDDLL = LoadLibrary((LPCWSTR) filename.c_str());
int loadLibraryError = GetLastError();
if (hGetProcIDDLL == NULL)
{
string error = "Could not load DLL\n";
send(s, error.c_str(), error.length(), 0);
finishSocketWork(s, address);
cout << "Unable to load LIB, error code " << loadLibraryError << endl;
getchar();
return;
}
(这是大学的工作,我需要从客户端接收DLL,调用指定的函数并返回结果)。 .dll 传输效果很好——文件是平等的
【问题讨论】:
-
您确定将正确的路径传递给
LoadLibrary调用吗?错误126是ERROR_MOD_NOT_FOUND,这意味着找不到“模块”。您能否编辑您的问题以包含一个 Minimal, Complete, and Verifiable Example 来显示您在做什么?请read about how to ask good questions. -
@Someprogrammerdude 添加了我的代码。抱歉,我以为我缺少一些依赖项,没有必要提供我的代码
标签: c++ loadlibrary