|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThere 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 Using CFileVersionInfoUsing the class The following short example writes the application's version information to CFileVersionInfo fvi; // Retrieve version information for this module if (fvi.Create()) { // Print version information cout << _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 - ReferenceMost of the methods are self-explanatory. Here are the references for the methods expected parameters: CreateInitializes the object. SyntaxBOOL Create(HMODULE hModule = NULL); BOOL Create(LPCTSTR lpszFileName); Parameters
Return ValueReturns GetFileVersionRetrieves binary file version. SyntaxWORD GetFileVersion(int nIndex) const; Parameters
GetProductVersionReturns the binary product version. SyntaxWORD GetProductVersion(int nIndex) const; Parameters
RequirementsThis 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 supportThough I haven't tested it, there is no reason, why this should not work with Unicode. Implementation DetailsThe class simply uses the following Windows' "File Installation Library Functions" for retrieving the version information:
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 LPVOID lpInfo; UINT unInfoLen; VerQueryValue(lpData, _T("\\"), &lpInfo, &unInfoLen); VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &lpInfo, &unInfoLen);
The first matching language is used. The users's main and sub language are retrieved by using the Revision History
19 Jun 2002 - Initial Revision
|
||||||||||||||||||||||