Find DLL paths, versions at runtime?

How can I find out at runtime what DLLs my app
is using, their versions and paths?  The answer
should not require me to look through the source
for LoadLibrary() and such (it's an MFC app and
these calls may be buried in code I don't want to
wade through).
trovatoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Windows 9x, Windows 2000: Use Tool Help functions - Module32First, Module32Next.

Windows NT, Windows 2000: Use PSAPI functions - EnumProcessModules, GetModuleFileNameEx.

Once you get the file name, use the GetFileVersionInfoSize and GetFileVersionInfo functions to retrieve the version information.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trovatoreAuthor Commented:
OK, thanks; I'm leaving work now so I probably won't
try it till Thursday -- will grade it after I try it.
0
trovatoreAuthor Commented:
P.S. does this also work for OCXs ?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

chensuCommented:
>does this also work for OCXs?

Not sure. I doubt so.
0
MadshiCommented:
Well, OCXs are just another kind of dlls, so I think that should work for OCXs, too...
Just my opinion...

Regards, Madshi.
0
trovatoreAuthor Commented:
It doesn't work for OCXs.  Can we find these too?
0
trovatoreAuthor Commented:
Also I can't make it link when GetFileVersionInfo()
is included.  What lib do I have to link to?
0
chensuCommented:
>It doesn't work for OCXs.  Can we find these too?

Sorry, I have no idea.

>Also I can't make it link when GetFileVersionInfo()
is included.  What lib do I have to link to?

version.lib
0
trovatoreAuthor Commented:
Turns out I was wrong; it *does* pick up the OCXs
after all.  When I tried it before, the app just hadn't
used any controls yet that used the OCXs, so they
hadn't been loaded.
0
chensuCommented:
Great.
0
trovatoreAuthor Commented:
Well, I was disappointed: I thought I'd be able to
have the code find out if it was running on 95/98
or on NT and call the appropriate functions.  But
no; when I tried to run the app on NT, I got
  "The procedure entry point Module32Next could not
   be located in the dynamic link library KERNEL32.DLL"

So, unless you know another way around it, I guess I'll
have to move these calls into a little DLL and supply
different versions of the DLL depending on whether
the user's running 95/98 or NT.

A couple questions:

  1) will that work?  or will the two DLLs result in different .LIB
      files and produce different .EXE files?

  2) If someone's double-booting 95 and NT, can I
      just copy one version of the DLL into WINDOWS\SYSTEM
     and the other into WINNT\SYSTEM ?
0
trovatoreAuthor Commented:
Well, I was disappointed: I thought I'd be able to
have the code find out if it was running on 95/98
or on NT and call the appropriate functions.  But
no; when I tried to run the app on NT, I got
  "The procedure entry point Module32Next could not
   be located in the dynamic link library KERNEL32.DLL"

So, unless you know another way around it, I guess I'll
have to move these calls into a little DLL and supply
different versions of the DLL depending on whether
the user's running 95/98 or NT.

A couple questions:

  1) will that work?  or will the two DLLs result in different .LIB
      files and produce different .EXE files?

  2) If someone's double-booting 95 and NT, can I
      just copy one version of the DLL into WINDOWS\SYSTEM
     and the other into WINNT\SYSTEM ?
0
chensuCommented:
The correct way to do it is to use LoadLibrary and GetProcAddress to call the functions.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.