How to get file versions from MFC

I want to be able to scan through a set of dll files and print
out their versions to a edit box.  I can't figure out how to
get file version information from MFC or runtime libs.
LVL 1
bradakAsked:
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.

JPMartineauCommented:
You need to:

call GetModuleHandle() to get HMODULE.

call FindResource() RT_VERSION is what you're looking for. you'll get a HRSRC.

call LoadResource with that HRSRC.

Have fun!

JPM
0
JPMartineauCommented:
oops

You need to:

call GetModuleHandle() to get HMODULE.

call FindResource() RT_VERSION is what you're looking for. you'll get a HRSRC.

call LoadResource with that HRSRC.

Have fun!

JPM


0
bradakAuthor Commented:
I've tried this and it doesn't work.

The GetModuleHandle says:
The GetModuleHandle function returns a module handle for the specified module if the file has been mapped into the address space of the calling process.

So for example I'm trying to find out what version
of odbc32.dll is.  I tried to GetModuleHandle on it and it just fails.

What do I need to do map the file into the address space of the calling process?

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

chensuCommented:
Determine DLL version number
http://www.codeguru.com/dll/dll_version.shtml
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
JPMartineauCommented:
Sorry, I forgot to add this at the beginning:

You must first load up the DLL:

LoadLibrary()

The LoadLibrary function maps the specified executable module into the address space of the calling process.

After your version checking, you should unload any unused DLLs using FreeLibrary();

HMODULE hModule = ::LoadLibrary("shell32.dll");
0
bradakAuthor Commented:
I could never get this to work.  I figured a different way to do it, so I'm going to give you the points anyway.

I used the File Installation Library Functions.

void FileCheck(char* filename, CString* cs_ver)
{
      DWORD size, tmp;
      DWORD   no_use = 0;
      
      *cs_ver = "???";      //init it to unknown

      size = GetFileVersionInfoSize(filename, &tmp);

      if (size) {
            char* buf_pt = new char[size];    

            if (GetFileVersionInfo(filename, no_use, size, buf_pt)) {
                  VS_FIXEDFILEINFO* t_info;
                  UINT tsz;
                  if (VerQueryValue(buf_pt, "\\", (LPVOID*)&t_info, &tsz)) {                  
                        cs_ver->Format("%d.%d.%d.%d",
                              HIWORD(t_info->dwFileVersionMS), LOWORD(t_info->dwFileVersionMS),
                              HIWORD(t_info->dwFileVersionLS), LOWORD(t_info->dwFileVersionLS));
                  }
            }
            delete [] buf_pt;
      }
}
0
bradakAuthor Commented:
Boy, that formated bad...
0
chensuCommented:
Doesn't the code I point use the File Installation Library 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
System Programming

From novice to tech pro — start learning today.