c++ - 通过线程设置DllDirectory
问题描述
为了在不同的线程中使用不可重入的 DLL,我将它复制到 4 个不同的文件夹中。这很丑陋但强制性...这个 DLL 由我的应用程序手动加载并使用另一个子库(隐式链接到另一个子库)。所以我有这样的事情:
folder1/
lib1.dll
sublib.dll
folder2/
lib2.dll
sublib.dll
我设法加载了不同版本的 lib.dll(lib1 和 lib2),但加载的 sublib.dll 对于两者都保持不变。我尝试了 SetDllDirectory 和 AddDllDirectory,但它没有加载多个 sublib.dll。
for (size_t i { 1 }; i <= threadsCount; ++i)
{
SetDllDirectoryA(nullptr); // Reset.
//SetDllDirectoryA(""); // Plug "binary planting" security hole. `
SetDllDirectoryA(dirPath(i).c_str()); // folderX
HMODULE module = LoadLibraryExA(libPath(i).c_str(), nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS);
if (!module )
{
std::cout << "error loading dll" << std::endl;
return false;
}
// Used after
// FooPrototype foo = (FooPrototype) GetProcAddress(module, "foo");
}
// Run threads with the different 'foo'
是否可以加载 2 个 sublib.dll 实例?
谢谢 !
解决方案
推荐阅读
- java - 从android中的方法访问JSON数据
- php - 数据库设计:将文件分配给多个用户
- java - 在屏幕锁定的情况下处理音量按钮
- css - 当我在属性内容中使用 CSS3 函数 target-counter 时,iText7 不起作用
- bokeh - 用于补丁的 Bokeh Hovertool
- ios - 通过 AirDrop 共享的文件不完整
- c++ - 如何在派生自 PIMPL 基类的类中重用相同的 impl 析构函数?
- javascript - Next.js 页面中的 ag-grid 渲染
- c++ - 使用变量的类型作为模板参数
- javascript - 进入全屏模式后,从嵌入式 iframe 中删除 Youtube 品牌、标题文本等