2

how can one tell (using non-CLR C++) which DLLs is a given running process (by ID) using? With file system paths to those DLLs and EXE.

Thank you in advance.

Cartesius00
  • 23,584
  • 43
  • 124
  • 195
  • POssible dublicate http://stackoverflow.com/questions/450039/how-to-programmatically-get-dll-dependencies – Anton Semenov May 28 '11 at 15:09
  • @Anton: Loaded modules are different from dependencies, and that other question is .NET-focused. – Ben Voigt May 28 '11 at 16:00
  • @Ben Voigt: I said about duplicates according to accepted answer in that question. The answer covers EnumProcessModules function, which return 'runtime process dependencies' or all modules loaded in process. I just reread that question and it about static dependencies indeed, so you are absolutely right. – Anton Semenov May 28 '11 at 17:43
  • @Anton: You do have a point that even though the other question isn't exactly a dupe, the answer covers this question as well. – Ben Voigt May 28 '11 at 18:20
  • @Ben: Yes! It's strange but these different questions have same answer. Actually that answer is not answer for that question – Anton Semenov May 28 '11 at 18:40

1 Answers1

3

If you are trying to do this in code, you are probably looking for the EnumProcessModules function (or K32EnumProcessModules depending on operating system. See the link for more details). There is an EnumProcessModulesEx that can give you a little more more information. Simply give it a handle to the process you want to know which modules (DLLs) are loaded. If you don't know the handle, you can find it using EnumProcesses or OpenProcess if you know the PID.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
  • Here you can find sample code which demonstrates approach with `EnumProcessModules` function http://msdn.microsoft.com/en-us/library/ms682621%28VS.85%29.aspx – Anton Semenov May 28 '11 at 17:45
  • This question is explicitly for the current process, there's got to be a better p – Ditmar Wendt Apr 24 '15 at 04:21
  • @DitmarWendt this answer will work for other processes, too (as I already said in my answer). EnumProcessModules takes a handle to any process you want to enumerate. – vcsjones Apr 24 '15 at 11:05