Click here to Skip to main content
11,926,429 members (55,025 online)
Click here to Skip to main content
Add your own
alternative version


65 bookmarked

CFileVersionInfo - Retrieving a File's full Version Information Resource

, 18 Jun 2002
Rate this:
Please Sign up or sign in to vote.
A class that enables you to easily retrieve a file's version information.
<!-- Download Links --> <!-- Add the rest of your HTML here -->


There are many cases, when version information extracted from a file's version resource could be useful. One example is to test for needed DLL versions. Another one is to simply use the version information from an application to display it in the about-dialog of the application. If your application contains more than one language resources, changing the version number becomes a boring task if you have to change the version label in each about-dialog. Using CFileVersionInfo you could simply read the version dynamically during runtime and insert it into the dialog. So you only will have to change the version resource when the version number of your application has changed.

Using CFileVersionInfo

Using the class CFileVersionInfo is very easy. Simply construct an object, call the Create() method to initialize the object with a file's version information and call the attribute operations to retrieve the required information.

The following short example writes the application's version information to stdout:

CFileVersionInfo  fvi;

// Retrieve version information for this module
if (fvi.Create())
    // Print version information
    << _T("Product: ") <<fvi.GetProductName()
    << _T("\n") << _T("Company: ")
    << fvi.GetCompanyName() << _T("\n")
    << _T("File Version Label: ")
    << fvi.GetFileVersion() << _T("\n")
    << _T("File Version Number: ")
    << fvi.GetFileVersion(3) << _T('.')
    << fvi.GetFileVersion(2) << _T('.')
    << fvi.GetFileVersion(1) << _T('.')
    << fvi.GetFileVersion(0);

CFileVersionInfo - Reference

Most of the methods are self-explanatory. Here are the references for the methods expected parameters:


Initializes the object.


BOOL Create(HMODULE hModule = NULL);
BOOL Create(LPCTSTR lpszFileName);


Module handle of the module, from which version information should be extracted. Specifying NULL creates an object that uses the version information of the module used to create the calling process.
Full path to the file, from which version information should be extracted.

Return Value

Returns TRUE if the version information has been extracted successfully and FALSE otherwise.


Retrieves binary file version.


WORD GetFileVersion(int nIndex) const;


Byte of the file version to return. 0 specifies the least significant and 3 the most significant byte.


Returns the binary product version.


WORD GetProductVersion(int nIndex) const;


Byte of the file version to return. 0 specifies the least significant and 3 the most significant byte.


This should run on Windows 95 or later and Windows NT 3.1 or later.

You will need to link your software with version.lib.

Unicode support

Though I haven't tested it, there is no reason, why this should not work with Unicode.

Implementation Details

The class simply uses the following Windows' "File Installation Library Functions" for retrieving the version information:

  • GetFileVersionInfo()
  • GetFileVersioninfoSize()
  • VerQueryValue

Retrieving the strings of the version information is a little bit tricky. Different from other resource's, where Windows chooses the language that best fits the user's preferences, for the version resource the developer is responsible for choosing the best matching language.

The datablock returned by GetFileVersionInfo() (lpData) contains a list of all language-codepage-combinations included in the datablock. One can receive this list using the following sequence:

LPVOID   lpInfo;
UINT      unInfoLen;
VerQueryValue(lpData, _T("\\"), &lpInfo, &unInfoLen);
VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &lpInfo, &unInfoLen);

CFileVersionInfo uses the following tests to get the best matching strings:

  1. Checks if version information is available that matches the user's main and sub language.
  2. Checks if version information is available that matches the user's main language.
  3. Checks if version information marked as "neutral" (LANG_NEUTRAL) is available.
  4. Checks if version information in English language (LANG_ENGLISH) is available.
  5. Uses the first language from the language list.

The first matching language is used. The users's main and sub language are retrieved by using the GetUserDefaultLangID() function.

Revision History

19 Jun 2002 - Initial Revision
19 Jun 2002 - Reformatted and rewrote some sections


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Sven Wiegand
Web Developer
Germany Germany
Sven Wiegand (1976), IT professional living in Berlin (Germany), develops open source software in his free time. His most successfull project is the LaTeX IDE TeXnicCenter which is distributed under the terms of the GNU-GPL and has more than 100,000 users all about the world.

"The picture shows me with my racing bike on the top of the Roque de los Muchachos (2426m) - the highest point of the canarian island La Palma."

You may also be interested in...

Comments and Discussions

QuestionCurrent date in File Version Info Pin
Vijay Pate8-Feb-12 9:40
memberVijay Pate8-Feb-12 9:40 
QuestionSemantic Versioning Specification Pin
ddbug11-Nov-11 20:54
memberddbug11-Nov-11 20:54 
GeneralYou are the best Pin
turkim2-Oct-10 12:37
memberturkim2-Oct-10 12:37 
GeneralUNICODE Problem Pin
Aric Green19-Mar-10 5:38
memberAric Green19-Mar-10 5:38 
Generalproblem Pin
Aric Green18-Mar-10 19:10
memberAric Green18-Mar-10 19:10 
GeneralThank you Pin
andrewtruckle16-Apr-09 0:39
memberandrewtruckle16-Apr-09 0:39 
GeneralLicense Pin
msvenc2-Aug-07 6:50
membermsvenc2-Aug-07 6:50 
AnswerRe: License Pin
Sven Wiegand2-Aug-07 22:26
memberSven Wiegand2-Aug-07 22:26 
GeneralExcellent Pin
waldermort13-Aug-06 13:33
memberwaldermort13-Aug-06 13:33 
GeneralA tip for Version.lib Pin
fader000313-Jul-06 10:29
memberfader000313-Jul-06 10:29 
I placed a pragma comment #pragma comment (lib, "version.lib")at the top of the FileVersionInfo.h (right under the #define AFX_FILEVERSION... line) to link to the Version.lib library. You could place this in the file the next time you update it and that would help alot of speedy programmers who don't like to read directions. Also I put a comment above the class declaration telling others to replace the "class AFX_EXT_CLASS CFileVersionInfo" with "class AFX_EXT_CLASS CFileVersionInfo" to avoid any confusion later. I'm not trying to tell you how to write your code, I just wanted to help since this was so helpful to me.
GeneralVisual Studio .Net Pin
Lea Robbo1-Mar-06 23:20
memberLea Robbo1-Mar-06 23:20 
GeneralFor linking to version.lib...just a tip, and if u get inconsistent dll linakge errors Pin
brrrrrr1-Dec-05 18:36
memberbrrrrrr1-Dec-05 18:36 
GeneralRe: For linking to version.lib...just a tip, and if u get inconsistent dll linakge errors Pin
Pandele Florin29-May-07 4:34
memberPandele Florin29-May-07 4:34 
GeneralRe: For linking to version.lib...just a tip, and if u get inconsistent dll linakge errors Pin
typical user19-Feb-09 8:36
membertypical user19-Feb-09 8:36 
GeneralLINK : warning LNK4089: Pin
Lea Rob27-Jul-05 5:46
sussLea Rob27-Jul-05 5:46 
GeneralWarning if running from network Pin
JonathanMerel4-Apr-05 10:27
memberJonathanMerel4-Apr-05 10:27 
GeneralUSEFUL!! Pin
SamGw4-Feb-05 23:46
memberSamGw4-Feb-05 23:46 
GeneralShared Folder Path Pin
Fawad Asrar Qureshi19-Dec-04 21:55
memberFawad Asrar Qureshi19-Dec-04 21:55 
Generaluse on VC7 Pin
Knuddlbaer24-Nov-03 0:24
memberKnuddlbaer24-Nov-03 0:24 
GeneralRe: use on VC7 Pin
Rail Jon Rogut15-Jul-04 7:31
memberRail Jon Rogut15-Jul-04 7:31 
GeneralThanks Pin
Zorglab4-Aug-03 11:13
memberZorglab4-Aug-03 11:13 
GeneralUnresolved external Pin
Al Newton23-Jan-03 12:24
memberAl Newton23-Jan-03 12:24 
GeneralRe: Unresolved external Pin
Sven Wiegand23-Jan-03 22:21
memberSven Wiegand23-Jan-03 22:21 
GeneralThank you.... Pin
rollasoc29-Aug-02 7:28
sussrollasoc29-Aug-02 7:28 
Generalproblem with exe Pin
Anonymous28-Aug-02 8:46
sussAnonymous28-Aug-02 8:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 19 Jun 2002
Article Copyright 2001 by Sven Wiegand
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid