473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

File version

Hi,

Does anyone know how to check a version of a file in C++? Any WIN32 API
that does this?

Please advice, thanks!
-P
Nov 17 '05 #1
1 1506
Hi Paul!
Does anyone know how to check a version of a file in C++? Any WIN32 API
that does this?


Here is susch a function:

<code>
// Returns
// - a negative value if an error occured (more information can be
retrived by calling "GetLastError")
// - "0" if the version is the same
// - "1" if the file-version is lower than the provided version
// - "2" if the file-version is higher than the provided version
int CompareFileVersion(LPCTSTR szFileName, WORD v1, WORD v2, WORD v3,
WORD v4)
{
LPVOID vData = NULL;
VS_FIXEDFILEINFO *fInfo = NULL;
DWORD dwHandle;
ULONGLONG ullVersion;
ullVersion = v4;
ullVersion |= (((ULONGLONG) v3) << 16);
ullVersion |= (((ULONGLONG) v2) << 32);
ullVersion |= (((ULONGLONG) v1) << 48);

DWORD dwSize = GetFileVersionInfoSize(szFileName, &dwHandle);
if (dwSize <= 0)
return -1;

// try to allocate memory
ULONGLONG fileVersion = 0;
vData = malloc(dwSize);
if (vData == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
return -1;
}

// try to the the version-data
if (GetFileVersionInfo(szFileName, dwHandle, dwSize, vData) == 0)
{
DWORD gle = GetLastError();
free(vData);
SetLastError(gle);
return -1;
}

// try to query the root-version-info
UINT len;
if (VerQueryValue(vData, _T("\\"), (LPVOID*) &fInfo, &len) == 0)
{
DWORD gle = GetLastError();
free(vData);
SetLastError(gle);
return -1;
}

// build the file-version
fileVersion = ((ULONGLONG)fInfo->dwFileVersionLS) +
((ULONGLONG)fInfo->dwFileVersionMS << 32);

free(vData);

// compare if the installed version is newer than this hotfix
if (fileVersion > ullVersion)
{
// The file is newer than the provided version
return 2;
}
else if (fileVersion < ullVersion)
{
// The file is older than the provided version
return 1;
}
return 0;
}
int _tmain()
{
CompareFileVersion(_T("c:\\DOTNETFX_v11.EXE"), 1, 1, 4322, 572);
}
</code>
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Bøcker-Larsen | last post by:
Hi I'v been stuck on this problem for ages now. I have found that I'm not the only one with this problem, by looking through the different newsgroups. Hope you can help me! I know there is a...
5
by: Laurence | last post by:
In VS.2005 using VB.NET There are two versions on every project, The Assembly Version and the File Version. Why are there two different versions? As far as I can tell, there is not need for...
1
by: Jerry John | last post by:
I am working in ASP.NET with C#. I have a text file which contains datas with delimiters. For example:- MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939| I also have an XML file created...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
3
by: seb | last post by:
Hi, I am writing to a file some basic information using the logging module. It is working but in the log file some line are printed several time. I had put some print debugging messages in the...
4
by: mcterborg | last post by:
Hello everyone, here is what I want to do. I have a ATI video card and it allows me to setup profiles for monitor configurations and so forth. The shortcut to activate one of these profiles looks...
7
by: dm3281 | last post by:
Hello, I have this non-standard XML file that I have to manually sort thru each day and verify whether various jobs finish successfully or not. This file isn't a real XML file, so I cannot appear...
4
by: Bob Altman | last post by:
Hi all, I have a C++/CLI project (VS 2005) that produces a DLL that exports C bindings. Internally, this DLL contains routines compiled with /clr. I notice that my DLL doesn't have a version...
4
by: nightscorpion | last post by:
Hello Gurus, i implemented the OpenFileDialog in my Windows Form Applications and it worked perfectly fine.However when it was run on a remote desktop i got the below error . ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.