0

I need to check for a given dll if all DLLs it depends on are present. I was able to get the list of DLLs using the code given in this question: How to programatically read native DLL imports in C#?. It gives the list of DLLs, including system ones (like kernel32.dll and others). What I need is to remove them from this list, as I do not need to check them, I only need to check the DLLs explicitly imported by developer.

Any ideas how to do that?

Community
  • 1
  • 1
Dmitrii Erokhin
  • 1,347
  • 13
  • 31

1 Answers1

3

There is no distinction whatsoever between Windows DLLs and 'regular' DLLs. The programmer actually did explicitly create a dependency on them, it doesn't happen by accident. And you do have to check them, it may require a DLL that is, say, only available on a later version of Windows.

More seriously, there are a lot of ways in which your approach won't work reliably. You'll never be able to figure out when it is using a DLL from the Windows side-by-side cache for example. You can't reasonably get into the business of parsing manifests. It is also very common for DLLs to have dynamic dependencies on other DLLs instead of static dependencies that you reverse-engineer from the IAT. This is true for COM as well as .NET assemblies for example.

There is only one good way to find out if the required DLLs are present. Load the DLL.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thank you. Loading the required dlls suites my needs perfectly. However is there any way to get the path where this needed dll is located without searching directories for it? – Dmitrii Erokhin Jun 17 '11 at 10:53
  • Yes, the path is where you hit the wall quite hard. The MSDN Library has some documentation on how Windows searches for DLLs in the article for SetDllDirectory. But this doesn't handle the case of manifest based activation or dynamic DLL loading. Both quite common these days. – Hans Passant Jun 17 '11 at 10:58