Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How would I go about examining an executables dependencies (e.g. dlls) programatically?
Posted

Read about the PE format and try to extract information out of it. PE format is the format on Windows for .exe, .dll etc .
 
Share this answer
 
Comments
Nish Nishant 21-Oct-10 7:09am    
My vote of 5! Good answer.
Use the Dependency Walker (depends.exe)[^] in command line mode: it does the work you require and send its output to the console. What you need is to spawn its process, attach its output and finally parse what it gives you.

[edit]

After searching a bit on internet, I found these pages:



There are some sample code and useful informations about how to do it.
 
Share this answer
 
v2
Comments
mbb01 21-Oct-10 7:56am    
This would appear to be a good utility, but the fact I cannot bundle it with another product might be limiting.
Sauro Viti 21-Oct-10 8:13am    
I understand your requirement! Unfortunately this means that probably you should do it in the hardest way (i.e. writing your code to handle the PE format); however I found some link that could be useful (see my updated answer)! Good luck!
mbb01 21-Oct-10 9:53am    
Thanks. Actucally the Dependency Walker is a very good tool. When it profiles it logs out what calls are being made as a program functions, so I can use it to analyse whether an app uses GDI or DirectX. It would be a wet dream to get my application to dynamically determine which library is being used and act accordingly. Your links will be helpful, but for now Dependency Walker will do the trick.
On quick caveat to bear in mind here is that about all you'll be able to work out are the load time or linker supported delay loaded dependencies. If someone's manually loading a DLL then it's a lot harder to detect (although you can get an inkling from the fact that the EXE imports LoadLibrary/GetProcAddress). Things like COM object activation are also hard to track for the same reasons.

Cheers,

Ash
 
Share this answer
 
Bleeding Fingers has answered you already on how to do this. But if the executable is currently running, then you may not need to do that and could instead use the EnumProcessModules API function.
 
Share this answer
 
Comments
[no name] 21-Oct-10 8:09am    
Oh thanks and yours is equally good and I have to five it (not returning) :)
Nish Nishant 21-Oct-10 8:14am    
Thanks, oddly someone seems to have down voted my reply. Not sure why!
[no name] 21-Oct-10 8:32am    
No no, it happened after I gave you five! I am damn sure I fived you and was surprised as well. Wanted to ask about this on the forum but decided to wait and watch because first, things seem to look alright after a while and second, the third answer in my list keeps fluctuating between perfect four votes of five and that decimal!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900