简体   繁体   中英

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. 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

// 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. 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. 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.

I don't want to load all DLLs searched all the time. 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-1.DLL has dependency on A.DLL, however.

I wonder if it is suggested class A is statically linked into A-1.dll rather than dynamically for my situation?

use AddDllDirectory API to add new search directory the the PATH; check API declaration from MSDN https://msdn.microsoft.com/en-us/library/windows/desktop/hh310513%28v=vs.85%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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