How to check for DLL dependency?

2019-01-01 10:39发布

Sometimes when I'm doing a little project I'm not careful enough and accidently add a dependency for a DLL that I am not aware of. When I ship this program to a friend or other people "it doesn't work" because "some DLL" is missing. This is ofcourse because the program can find the DLL on my system, but not on theirs.

Is there a program/script that can scan an executable for DLL dependencies or execute the program in a "clean" DLL-free environment for testing to prevent these oops situations?

11条回答
何处买醉
2楼-- · 2019-01-01 11:11

In the past (i.e. WinXP days), I used to depend/rely on DLL Dependency Walker (depends.exe) but there are times when I am still not able to determine the DLL issue(s). Ideally, we'd like to find out before runtime by inspections but if that does not resolve it (or taking too much time), you can try enabling the "loader snap" as described on http://blogs.msdn.com/b/junfeng/archive/2006/11/20/debugging-loadlibrary-failures.aspx and https://msdn.microsoft.com/en-us/library/windows/hardware/ff556886(v=vs.85).aspx and briefly mentioned LoadLibrary fails; GetLastError no help

WARNING: I've messed up my Windows in the past fooling around with gflag making it crawl to its knees, you have been forewarned.

enter image description here

Note: "Loader snap" is per-process so the UI enable won't stay checked (use cdb or glfags -i)

查看更多
闭嘴吧你
3楼-- · 2019-01-01 11:14
  1. Press the start button, type "dev". Launch the program called "Developer Command Prompt for VS 2017"

  2. Figure out the full file path to the assembly you're trying to work with

  3. In the window that opens, type dumpbin /dependents [path], where [path] is the path you figured out in step 2

  4. press the enter key

Bam, you've got your dependency information. The window should look like this:

enter image description here

This took me an entire fucking hour to figure out. Hopefully it helps somebody in the future.

查看更多
笑指拈花
4楼-- · 2019-01-01 11:15

If you have the source code, you can use ndepend.

http://www.ndepend.com/

It's pricey and does a lot more than analyzing dependencies so it might be overkill for what you are looking for.

查看更多
裙下三千臣
5楼-- · 2019-01-01 11:20

dumpbin from Visual Studio tools (VC\bin folder) can help here:

dumpbin /dependents your_dll_file.dll
查看更多
十年一品温如言
6楼-- · 2019-01-01 11:20

Please search "depends.exe" in google, it's a tiny utility to handle this.

查看更多
登录 后发表回答