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.
out their versions to a edit box. I can't figure out how to
get file version information from MFC or runtime libs.
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
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
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ");
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
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(fil ename, &tmp);
if (size) {
char* buf_pt = new char[size];
if (GetFileVersionInfo(filena me, 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->dwFileVersi onMS), LOWORD(t_info->dwFileVersi onMS),
HIWORD(t_info->dwFileVersi onLS), LOWORD(t_info->dwFileVersi onLS));
}
}
delete [] buf_pt;
}
}
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(fil
if (size) {
char* buf_pt = new char[size];
if (GetFileVersionInfo(filena
VS_FIXEDFILEINFO* t_info;
UINT tsz;
if (VerQueryValue(buf_pt, "\\", (LPVOID*)&t_info, &tsz)) {
cs_ver->Format("%d.%d.%d.%
HIWORD(t_info->dwFileVersi
HIWORD(t_info->dwFileVersi
}
}
delete [] buf_pt;
}
}
ASKER
Boy, that formated bad...
Doesn't the code I point use the File Installation Library Functions?
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