简体   繁体   English

依赖其他DLL的DLL?

[英]DLL that depends on other DLLs?

Static linking is not an option. 静态链接不是一种选择。

Let's say that I have an executable that relies on a DLL. 假设我有一个依赖DLL的可执行文件。 One solution is to ship the DLL in the same folder as the executable. 一种解决方案是将DLL与可执行文件放在同一文件夹中。 Now let's say that I need to inject a DLL into a process that relies on a DLL. 现在,我们需要将DLL注入依赖DLL的进程中。 Because the DLL is injected, where would I put the DLLs that it relies on? 因为DLL是注入的,我将它依赖的DLL放在哪里? In the same folder? 在同一个文件夹中? Or in the directory of the process that is injected to? 还是在注入过程的目录中?

DLLs depending on one or more other DLLs is not something special. 依赖于一个或多个其他DLL的DLL没什么特别的。 Even a trivial DLL will have dependencies on Windows shared components which are residing in other DLLs. 即使是琐碎的DLL也将依赖于其他DLL中驻留的Windows共享组件。 A good example of these "shared components" would be Kernel32.dll and the CRT DLL such as MSVCR80.DLL etc. 这些“共享组件”的一个好例子是Kernel32.dll和CRT DLL,例如MSVCR80.DLL等。

You can find out exactly which other DLLs your DLL or EXE requires on by invoking the Dependency Walker . 您可以通过调用Dependency Walker来确切地找到您的DLL或EXE需要哪些其他DLL。 To do that, just run depends.exe from a Visual Studio Command Prompt and drag-and-drop the DLL of interest into the Window that appears. 为此,只需运行Visual Studio命令提示符中的depends.exe ,然后将感兴趣的DLL拖放到出现的窗口中即可。 In case you don't have dependency walker available, you can download it from the above link. 如果您没有可用的依赖遍历器,可以从上面的链接下载它。

I'm not sure of the DLL injection stuff, but it should generally be sufficient if you place all your (other DLL) dependencies in the same folder as your DLL, which would be the folder in which the EXE loading these DLLs resides. 我不确定DLL注入的内容,但是如果将所有(其他DLL)依赖项放在与DLL相同的文件夹中,则通常就足够了,该文件夹就是加载这些DLL的EXE所在的文件夹。

Eg: If C:\\test\\foo.exe requires bar.dll (which in turn requires baz.dll , assuming baz.dll is not a standard windows shared component), then you would place both bar.dll and baz.dll in C:\\test . 例如:如果C:\\test\\foo.exe需要bar.dll (反过来又需要baz.dll ,假设baz.dll不是标准的Windows共享组件),那么您将bar.dllbaz.dll放在C:\\test

There is a lot more to how the OS determines which DLL to load, since multiple versions of the same DLL may exist at various locations and MSDN has a helpful article on the search order for dynamic linked libraries. 操作系统确定要加载哪个DLL的方式还有很多,因为同一DLL的多个版本可能存在于各个位置,并且MSDN上有一篇有关动态链接库的搜索顺序的有用文章

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

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