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?
 
chensuConnect With a Mentor Commented:
Determine DLL version number
http://www.codeguru.com/dll/dll_version.shtml
0
 
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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

From novice to tech pro — start learning today.