1
votes

I have A.DLL that depends on B.DLL. A.DLL contains some initialization code (DllMain) that registers stuff with B.DLL.

I also have executable E.EXE that does not directly reference any A.DLL symbols but it uses A.DLL's stuff through generic interfaces obtained from B.DLL.

The problem is that A.DLL is never loaded into E.EXE's process because none of its exported symbols are imports of E.EXE.

Can I force A.DLL to be loaded into the process without actually referencing A.DLL's symbols in E.EXE and without inverting the dependency (or creating a dependency loop) between A.DLL and B.DLL, and without using explicit LoadLibrary() call?

EDIT: The problem has been produced on Windows with Visual Studio but portability is a concern, thus LoadLibrary() is not usable.

1
What's wrong with LoadLibrary(). It's a single line of code! - David Heffernan
What purpose does putting the DLL into the process serve here? - JaredPar
@DavidHeffernan: It is not portable and I do not want to deal with security issues related to manual DLL loading. - wilx
@wilx: not portable to which platform? - Igor Korkhov
@wilx Can't believe you forgot to mention portability. You only get DLLs on Windows! And as for security issues, what security issues? Implicit linking is no different from LoadLibrary and indeed with LoadLibrary you can control which DLL you load. You can't with implicit linking. - David Heffernan

1 Answers

7
votes

You can specify the /INCLUDE linker option and provide a symbol exported by A.dll.

Even though your executable does not really reference that symbol, that option will force the linker to add A.dll to the dependencies.