Link to home
Start Free TrialLog in
Avatar of bradak
bradak

asked on

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.
Avatar of JPMartineau
JPMartineau

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
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


Avatar of bradak

ASKER

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?

ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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");
Avatar of bradak

ASKER

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;
      }
}
Avatar of bradak

ASKER

Boy, that formated bad...
Doesn't the code I point use the File Installation Library Functions?