简体   繁体   English

如何导出依赖于其他 DLL 的 DLL?

[英]How to export DLLs that have dependency on other DLLs?

Say I have an EXE main program that searches for DLLs in a folder "plugins\\" and its subfolders, and then list the Plugin names of all available DLLs.假设我有一个 EXE 主程序,它在文件夹“plugins\\”及其子文件夹中搜索 DLL,然后列出所有可用 DLL 的插件名称。 The folder structure looks like below.文件夹结构如下所示。

EXE
  |
  |--plugins\
       |
       |--A\   --> A.dll
       |--A-1\ --> A-1.dll
       |--B\   --> B.dll

Each DLL export a Plugin class like below每个 DLL 导出一个 Plugin 类,如下所示

// A.DLL
class __declspec(dllexport) A : PluginBase
{
public:
    void virtual Func( void );
};

// A-1.DLL
class __declspec(dllexport) A_1 : public A
{
public:
    void virtual Func( void );
};

// B.DLL
class __declspec(dllexport) B: public PluginBase
{
public:
    void virtual Func( void );
}

All three DLLs are located in different folders.所有三个 DLL 都位于不同的文件夹中。 In some situations, it is not desirable that folder "A\\" and A.dll is shown for users, but only folder "A-1\\" and A-1.dll is shown.在某些情况下,不希望向用户显示文件夹“A\\”和 A.dll,而只显示文件夹“A-1\\”和 A-1.dll。 However, when A-1.dll is loaded by LoadLibrary(), A.dll must exist and searchable, when A-1.dll is dynamically linked with A.dll.但是,当 LoadLibrary() 加载 A-1.dll 时,当 A-1.dll 与 A.dll 动态链接时,A.dll 必须存在且可搜索。

I don't want to load all DLLs searched all the time.我不想加载一直搜索的所有 DLL。 Instead, I want to load A.DLL when users select Plugin A, B.DLL when users select Plugin B, and A-1.DLL when users select Plugin A-1.相反,我想在用户选择插件 A 时加载 A.DLL,当用户选择插件 B 时加载 B.DLL,当用户选择插件 A-1 时加载 A-1.DLL。 A-1.DLL has dependency on A.DLL, however.但是,A-1.DLL 依赖于 A.DLL。

I wonder if it is suggested class A is statically linked into A-1.dll rather than dynamically for my situation?我想知道是否建议 A 类静态链接到 A-1.dll 而不是动态链接到我的情况?

use AddDllDirectory API to add new search directory the the PATH;使用 AddDllDirectory API 在 PATH 中添加新的搜索目录; check API declaration from MSDN https://msdn.microsoft.com/en-us/library/windows/desktop/hh310513%28v=vs.85%29.aspx从 MSDN https://msdn.microsoft.com/en-us/library/windows/desktop/hh310513%28v=vs.85%29.aspx检查 API 声明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM