http://www.codeguru.com/Cpp/W-P/win32/versioning/article.php/c4539/
Internet.com - The Network for Technology Professionals
* > IT
o internet.com/IT
o internet.com/CIO
o internet.com/Security
o internet.com/Networking
o internet.com/Storage
o bITa Planet
o CIO Update
o Database Journal
o Datamation
o Enterprise IT Planet
o Enterprise Networking Planet
o Enterprise Storage Forum
o eSecurity Planet
o Hardware Central
o Intranet Journal
o ISP Planet
o ITSMwatch
o IT Channel Planet
o Linux Planet
o Open Networks Today
o ServerWatch
o VoIP Planet
o WebVideoUniverse
o Wi-Fi Planet
o WinDrivers.com
o Network Map
* > Developer
o internet.com/Developer
o 15 Seconds
o 4GuysFromRolla.com
o ASP101
o CodeGuru
o Developer.com
o DevX
o FlashKit.com
o Gamelan
o JARS
o JavaScript.com
o JavaScriptSource
o PHPBuilder.com
o ScriptSearch
o VB Forums
o VB Wire
o WebDeveloper.com
o Webreference
o Network Map
* > News
o Internetnews.com
o Linux Today
o Network Map
* > Small Business
o Ecommerce Guide
o Refer-It
o SmallBusinessComputing
o Webopedia
o WinPlanet
o Network Map
* > Personal Tech
o BlackBerryToday
o iPhoneGuide
o Jumbo
o Megapixel.net
o Palm Boulevard
o PDAStreet
o PocketPCWire
o SharkyExtreme
o Smart Phone Today
o The List: ASPs
o The List: Broadband
o The List: ISPs
o The List: WebHosts
o The List: WebDesigners
o Wi-FiHotSpotList
o WindowsMobileToday
o Network Map
* > Events
o JupiterEvents
o internet.com/webcasts
* Jobs
* Partners
* > Solutions
o eBooks
o Video
* Shop
* > Login
o Manage My Profile
* >Register
o Why Join?
IT MANAGEMENT
CIO Update
Datamation eCRMGuide
DRM Watch eSecurity Planet
ITSMWatch Intranet Journal
Inside ID Grid Computing Planet
bITa Planet IT Career Planet Planet
NETWORKING
EnterpriseNetworkingPlanet
InstantMessagingPlanet EnterpriseStorageForum
OpenNetworksToday OpticallyNetworked
PracticallyNetworked
WEB DEVELOPMENT
HTML Goodies
Javascripts.com
HARDWARE & SYSTEMS
EarthWeb Hardware
SysOpt Virtual Dr.
WorkstationPlanet
SOFTWARE DEVELOPMENT
CodeGuru
Developer jGuru.com
JARS Gamelan
EARTHWEBNEWS.COM
Business
Developer Ecommerce
Enterprise Networking
Security Special Reports
Storage Commentary
Wireless xSP
Stats
* IT MANAGEMENT
* NETWORKING
* WEB DEVELOPMENT
* HARDWARE & SYSTEMS
* SOFTWARE DEVELOPMENT
* IT NEWS
CodeGuru
Earthweb Search
CodeGuru Navigation
* Visual C++ / C++
o C++ »
+ Algorithms & Formulas
+ C++ & MFC
+ Date & Time
+ Managed C++
+ String Programming
o COM-based Technologies »
+ ATL & WTL Programming
+ ActiveX Programming
+ COM+
+ Shell Programming
o Controls »
+ Button Control
+ ComboBox
+ Edit Control
+ ImageList Control
+ ListBox Control
+ ListView Control
+ Menu
+ Other Controls
+ Property Sheet
+ Rich Edit Control
+ Static Control
+ Status Bar
+ Toolbar
+ Treeview Control
o Data »
+ Database
+ Miscellaneous
o Frameworks »
+ UI & Printing Frameworks
o Graphics & Multimedia »
+ Bitmaps & Palettes
+ DirectX
+ GDI
+ Multimedia
+ OpenGL
o Internet & Networking »
+ IE Programming
+ ISAPI
+ Internet Protocols
+ Network Protocols
o Miscellaneous »
+ Miscellaneous
+ Samples
o Security
o Standard Template Library
o Visual Studio »
+ Add-ins & Macros
+ Debugging
+ Editor Tips
o Windows & Dialogs »
+ Console
+ Dialog
+ Doc/View
+ Docking Window
+ Splitter
o Windows Programming »
+ CE
+ Clipboard
+ DLL
+ File & Folder
+ Help Systems
+ Printing
+ System
+ Vista
+ Win32
o Sample Chapter
* .NET / C#
o .NET »
+ Data & Databases
+ Debugging
+ Framework
+ General
+ General ASP.NET
+ JScript .NET
+ Managed C++
+ Net Security
+ VS Add-Ins
+ Silverlight
+ WCF
+ WPF
+ Windows Workflow
o C# »
+ Basic Syntax
+ Collections
+ Controls
+ Data & I/O
+ Date & Time
+ Delegates
+ Graphics & Multimedia
+ Internet
+ Miscellaneous
+ .NET 3.0 / .NET 3.5
+ Network & Systems
+ Web Services
+ LINQ
o Sample Chapter
* Visual Basic
o General »
+ Database
+ Forms & Controls
+ IDE & Language
+ Misc
+ System
+ VB Graphics
+ VB Multimedia
o Internet »
+ ASP .NET
+ Database
+ HTML
+ Indexing
+ SMTP / eMail
+ Web Services
o Mobile/Wireless »
+ Mobile Internet
Toolkit
+ Pocket PC
o .NET 3.0
o LINQ
o VB Controls »
+ .NET Controls
+ VB ActiveX
+ VB ComboBox
+ VB Files
+ VB ListBox
+ VB ListView
+ VB Other Controls
+ VB Shell
o Sample Chapter
* Videos
* Submit an Article
* Discussion Forums
* Resource Directory
* Announcements
* Book List
* Book Reviews
* List of Gurus
* Guest Book
* Technology Jobs
* About Us
* FAQs
* Site Map
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.
Become a Marketplace Partner
Build mobile apps, win €15,000 & a trip to Spain
jobs.internet.com
internet.commerce
Partners & Affiliates
KVM Switch over IP
Domain registration
Promotional Products
Computer Hardware
Compare Prices
Disney World Tickets
Find Software
Shop Online
Promotional Golf
Online Shopping
Shop
Phone Cards
Car Donations
Logo Design Custom
RSS Feeds
RSSAll
RSSVC++/C++
RSS.NET/C#
RSSVB
See more EarthWeb Network feeds
Home >> Visual C++ / C++ >> Windows Programming >> Win32 >> Versioning
Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.
Versioning in Windows
Rating: none
Henri Hein (view profile)
October 24, 2003
Environment: Visual Studio 6.0. Uses STL.
Windows has a built-in version concept, and it's a good idea to make use of this by version stamping all your binary modules. By doing this, you gain the following advantages:
* Users can easily identify the version of your program that they are using.
* When you load a module, you can verify its version much more reliably with a version stamp than using a date stamp.
* Some Windows components, such as the Windows Installer, use the version stamp to secure against overriding a newer module with an older one.
(continued)
Download these IBM resources today!
e-Kit: IBM Rational Systems Development Solution
With systems teams under so much pressure to develop products faster, reduce production costs, and react to changing business needs quickly, communication and collaboration seem to get lost. Now, theres a way to improve product quality and communication.
Webcast: Asset Reuse Strategies for Success--Innovate Don't Duplicate!
Searching for, identifying, updating, using and deploying software assets can be a difficult challenge.
eKit: Rational Build Forge Express
Access valuable resources to help you increase staff productivity, compress development cycles and deliver better software, fast.
Download: IBM Data Studio v1.1
Effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life.
eKit: Rational Asset Manager
Learn how to do more with your reusable assets, learn how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse.
A module in this article refers to either an executable or a dll.
Why Is a Version Stamp Better than a Date Stamp?
Because a date stamp gets changed and updated after build time. For instance, if your application gets written to a CD, the date stamp is whatever the burner software assigns at write time. If a user downloads a module from the Internet or extracts it from a zip file, the date stamp marks the time the file was created through one of these actions. Various utilities also touch the date stamp. You could potentially have a newer build from older sources. In short, there is no correlation between the date stamp and the sources comprising the build.
A version stamp, on the other hand, can tell you exactly when that module was built. It also can capture some other information, such as what the original filename was, in case the module gets renamed. It contains company and legal information as well.
Version Stamp Anatomy
The main part of the version stamp is the version itself. There are four parts to the version. A sample version looks like this: 2.1.3.37.
A version resource in Windows has twelve fields altogether. Examples are "CompanyName," "FileDescription," and "LegalCopyright." There are two version fields, one for the file and one for the product. These often will be the same, but can be different when you release patches for a product. For instance, say your product consists of an executable and two DLLs. If you release a version of the product, and later release an update to one of the DLLs, that module will have a different file version number from the others.
Assigning a Build Number
There are different philosophies on how to assign build numbers. One approach, described in the Microsoft Support Article On Auto Incrementing Build Numbers, is to increase the build number every time the build script executes. The advantage to this approach is that each build is guaranteed to have a unique build number. The disadvantage is that there is no correlation between a build number and when the build was performed. This is more than a hypothetical situation because builds are performed rarely at the beginning of the development cycle, more frequently towards the end.
Another approach is to make the build number be determined by when the build was done. A typical way to do this is by counting the number of days from a given day—for instance, the project's start—to the day of the build. The advantage to this approach is that for any given version, a support rep or engineer can determine when that build was done. The disadvantage is that multiple builds on the same day will get the same build number.
Personally, I prefer the latter approach. After building software for twelve years, I have run into having to perform separate builds on the same day twice. (Performing the same build more than once should result in the same build number). In neither case was it a big problem. Checking in a version of the Resource Script with zero as the build number, then having the official build script assign the number each time, also allows users, engineers, and others to distinguish between official builds and private builds done by developers.
Usage
Adding a version stamp to any module, whether a DLL or executable, is simple. A version stamp is a type of resource. To add the version information, use "Insert/Resource," and choose the bottom entry in the resource type list: Version. This will insert a default version stamp. In your resource script, it will be called "VS_VERSION_INFO;" do not change this name.
A user can examine the version information from the Explorer. By right-clicking the module, choosing "Properties" from the context menu, and then clicking the "Version" tab, the version stamp is presented in the properties window.
If a module does not have a version stamp, the "Version" tab does not appear in the Explorer properties dialog.
Following is a sample of the version resource in the RC file. It corresponds to the version properties window displayed below. You would rarely need to edit the version resource directly.
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,0,249
PRODUCTVERSION 1,1,0,249
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Hewlett-Packard Company\0"
VALUE "FileDescription", "HPVersioner\0"
VALUE "FileVersion", "1, 1, 0, 249\0"
VALUE "InternalName", "HPVersioner\0"
VALUE "LegalCopyright", "Copyright ) 2003\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "HPVersioner.exe\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "HPVersioner -- Commandline
Version Markup Utility\0"
VALUE "ProductVersion", "1, 1, 0, 249\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
To use this resource from your code, you access a VS_FIXEDFILEINFO structure. You don't get this by the normal FindResource()/LoadResource() API functions. Instead, use GetFileVersionInfo() and VerQueryValue(). To load the version information from a file, use the following lines:
DWORD dwLen, dwUseless;
LPTSTR lpVI;
std::string companyName;
UINT verMajor;
dwLen = GetFileVersionInfoSize((LPTSTR)szFile, &dwUseless);
if (dwLen==0)
return 0;
lpVI = (LPTSTR) GlobalAlloc(GPTR, dwLen);
if (lpVI)
{
DWORD dwBufSize;
VS_FIXEDFILEINFO* lpFFI;
BOOL bRet = FALSE;
WORD* langInfo;
UINT cbLang;
TCHAR tszVerStrName[128];
LPVOID lpt;
UINT cbBufSize;
GetFileVersionInfo((LPTSTR)szFile, NULL, dwLen, lpVI);
if (VerQueryValue(lpVI, _T("\\"),
(LPVOID *) &lpFFI, (UINT *) &dwBufSize))
{
//We now have the VS_FIXEDFILEINFO in lpFFI
verMajor = HIWORD(lpFFI->dwFileVersionMS);
}
//Get the Company Name.
//First, to get string information, we need to get
//language information.
VerQueryValue(lpVI, _T("\\VarFileInfo\\Translation"),
(LPVOID*)&langInfo, &cbLang);
//Prepare the label -- default lang is bytes 0 & 1
//of langInfo
wsprintf(tszVerStrName, _T("\\StringFileInfo\\
%04x%04x\\%s"),
langInfo[0], langInfo[1], _T("CompanyName"));
//Get the string from the resource data
if (VerQueryValue(lpVI, tszVerStrName, &lpt, cbBufSize))
companyName.assign((LPTSTR)lpt); //*must* save this
//Cleanup
GlobalFree((HGLOBAL)lpVI);
}
Notice that we don't have to clean up after each call to VerQueryValue(). We delete the lpVI pointer at the end. This also invalidates all the string values, so we must save the strings into other variables before we free lpVI.
Wrapper Class and HPVersioner Utility
Attached to this article are two useful downloads.
The first is a Version update utility, HPVersioner. It will find a VS_VERSION_INFO structure in your RC file and update it with the build number du jour. It follows the time-based approach, as described above. For information on the syntax and usage of HPVersioner, download the utility zip file and look at Readme.txt.
The other download is the sources for HPVersioner. This includes a class, CVersionInfo, that provides easy access to a version stamp. A CVersionInfo object can populate itself from a string (of the form "1.0.2.17"), an HMODULE, a VS_FIXEDFILEINFO, another CVersionInfo, and so forth. If instantiated from an HMODULE or a file, it populates three strings from the version stamp: ProductName, CompanyName, and LegalCopyright. Other strings will be easy to add.
The CVersionInfo constructor that takes a string will parse the string as a version info, such as "1.0.2.17". This will not populate ProductName, CompanyName, or LegalCopyright. To load version info from a file, use the method SetFromFilename().
We generally expect version numbers to appear separated by the period, such as "1.2.1.23." In the RC file, the version numbers are separated by comma, as in "1,2,1,23." For this reason, CVersionInfo has the capability to render itself in either format. The former is called AsString(); the latter is AsResource().
CVersionInfo contains assignment and comparison operators. This allows you to easily manipulate and compare versions of modules. You can also use the CVersionInfo class to easily display version stamp information in your About box or Splash screen.
Sample usage of the CVersionInfo class:
HINSTANCE hmodDll = LoadLibrary(_T("MyAppMod.dll"));
if (hmodDll)
{
CVersionInfo verApp(GetModuleHandle(NULL));
CVersionInfo verModule(hmodDll);
//Don't use the module if it's older than the app
if (verModule < verApp)
{
FreeLibrary(hmodDll);
hmodDll = NULL;
}
}
Conclusion
Adding a version stamp to your modules is easy, and will allow you to perform robust versioning checks, display data about your modules to the user, and keeps the system informed about the sequence of your releases.
Downloads
Download HPVersioner utility - 27 Kb
Download source - 9 Kb
Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed
Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.
Is it time to make your move to the multi-threaded and parallel processing world? Find out!
Learn about expanding business opportunities for the reseller channel. Visit IT Channel Planet.
RATE THIS ARTICLE: Excellent Very Good Average Below Average Poor
(You must be signed in to rank an article. Not a member? Click here to register)
Latest Comments:
• This article already been published by Paul DeLaSia on MSDN - Legacy CodeGuru (10/27/2003)
• Your search.... on MSDN - Legacy CodeGuru (10/27/2003)
• Additional Version Information - Legacy CodeGuru (10/24/2003)
View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)
(You must be signed in to comment on an article. Not a member? Click here to register)
JupiterOnlineMedia
internet.comearthweb.comDevx.commediabistro.comGraphics.com
Search:
Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia
Jupitermedia Corporate Info
Copyright 2008 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers
Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES