Click here to Skip to main content
15,169,508 members
Articles / Programming Languages / C++
Posted 23 Apr 2002


45 bookmarked

RCStamp - add build counts and more to your .rc files

Rate me:
Please Sign up or sign in to vote.
4.87/5 (22 votes)
23 Apr 2002CPOL3 min read
RCStamp is a flexible command line tool to modify the FILEVERSION entries in a .rc Resource script (source included)


File Version numbers in Windows consist of four positions with 16 bits each, e.g. 6.0.2600.0 is the version of my iexplore.exe. Typically you use the first two positions as "major.minor" version, based on the features of the module, the third position for an incremental build count, and the fourth for special builds. (You already knew all this, didn't you?)

RCStamp grew out of the necessity to manage a rather complex versioning scheme on a dozen of binaries. It can modify the FILEVERSION entry and the "FileVersion" string entry in a VERSIONINFO resource. It uses a format string that can affect the four positions of the version number individually. A typical call looks like this:

rcstamp myproject.rc *.*.+.*

This would increment the third position, and leave all others unmodified. You get a simple automatic build counter when you integrate this as custom build step into your Visual Studio project.

A more complex call:

rcstamp myproject.rc *.+.0.+1000

would increment the second position (minor version), set the third position to 0, and increment the fourth by 1000.

Command line options:

rcstamp file <format> [<options>...]
rcstamp @file [<format>] [<options>...]

Format options:

*leave position as-is
+increment position by one
nset the position to the number n (decimal)
+nincrement position by the number n (decimal)
-decrement position by one (if you ever need it)
-ndecrement position by the number n (still decimal, and you have been warned)

Additonal command line options:

-ndon't modify the "FileVersion" string value
-rRESIDmodify only the version resource with the resource id RESID (Default: modify all resources)
-vVerbose (echo the modified values)
-lProcess a list file instead of a resource (see below)

List Files

For batch processing, you can specify a text file containing a list of file names, like this:
rcstamp @files.txt *.*.+.*
files.txt could look like this:

You can add a format for an individual file (separated by a '=') to override the format specified at the command line.

-l - the Self-Awareness switch

The -l option allows to modify a list file like the one above, instead of a resource script. This is far from useful, since all special formattings will be rendered as 0, and I suspect a bug there. But it's a perfect example of the useless features you spend late hours with.

Return Values

Since it's intended for batching, there are some errorlevel's to evaluate:
ERRORLEVEL 3 : invalidarguments
ERRORLEVEL 1 : an error occured when processing at least
      one file (error message written to stderr)
ERRORLEVEL 0 : everything's fine


The sources are pretty straightforward, it doesn't rely on any library (besides the VC runtime). main() clobbers the command line, and then processes either the specified file, or opens the file list and processes each of the files. ParseArg() will analyze one command line parameter at a time, and store it's findings in global variables. ProcessFile() will process a single file according to the options set. CalcNewVersion() calculates the new file version from a string containing the old one and a format specifier.

The files are read with std::ifstream line-by-line, The modified text is collected in a std::string, and then the entire file is overwritten.


This is a one-nighter (a half-nighter, even) - I didn't test everything (e.g. the '-' format specification, and the -l option), there are some potential buffer overruns and when you run out of memory it will look ugly. The file parsing is homegrown, it doesn't really "understand" the .rc file; it just looks for certain tokens, using of strdup and strtok. it is fairly stable with the .rc files produced by Visual Studio, but it might fail in exotic cases (I didn't even dive into the .rc documentation so I don't know what is allowed).

Oh, and you might already have guessed - you can't decrement the first position, since the leading '-' is interpreted as option. Since this tool is in daily use (I use it now for the daily builds at work, and for preparing releases) I for sure will fix the bugs that appear in the features I need. Beyond that, it's up to you - at least, up to your persuasion skills.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Germany Germany
Peter is tired of being called "Mr. Chen", even so certain individuals insist on it. No, he's not chinese.

Peter has seen lots of boxes you youngsters wouldn't even accept as calculators. He is proud of having visited the insides of a 16 Bit Machine.

In his spare time he ponders new ways of turning groceries into biohazards, or tries to coax South American officials to add some stamps to his passport.

Beyond these trivialities Peter works for Klippel[^], a small german company that wants to make mankind happier by selling them novel loudspeaker measurement equipment.

Where are you from?[^]

Please, if you are using one of my articles for anything, just leave me a comment. Seeing that this stuff is actually useful to someone is what keeps me posting and updating them.
Should you happen to not like it, tell me, too

Comments and Discussions

QuestionOutdated Pin
Serjinator24-Feb-16 2:47
MemberSerjinator24-Feb-16 2:47 
Questionremove all in rc file after using RCstamp comand. Pin
Mạnh Lê22-Dec-15 22:02
MemberMạnh Lê22-Dec-15 22:02 
SuggestionIntegrating into VS2008 Pin
softwaremonkey5-Mar-13 7:41
Membersoftwaremonkey5-Mar-13 7:41 
GeneralUnicode rc files Pin
ThomT21-Dec-06 1:27
MemberThomT21-Dec-06 1:27 
GeneralProblems with ',' and '.'? What about ProductVersion? Here comes an improved version... Pin
knaster bax28-Dec-05 7:49
Memberknaster bax28-Dec-05 7:49 
GeneralRe: Problems with ',' and '.'? What about ProductVersion? Here comes an improved version... Pin
Sir Athos22-Sep-06 7:57
MemberSir Athos22-Sep-06 7:57 
GeneralThanks! Pin
hairyfellow27-Jul-05 12:21
Memberhairyfellow27-Jul-05 12:21 
GeneralDaily Builds - Build Manager Pin
Anonymous27-Jun-05 5:54
MemberAnonymous27-Jun-05 5:54 
GeneralFollowup Tool Pin
peterchen19-May-05 6:39
Memberpeterchen19-May-05 6:39 
GeneralNaming output files according to version/build numbers Pin
Beau Skinner5-May-05 12:17
MemberBeau Skinner5-May-05 12:17 
GeneralRe: Naming output files according to version/build numbers Pin
peterchen5-May-05 12:34
Memberpeterchen5-May-05 12:34 
GeneralRe: Naming output files according to version/build numbers Pin
Beau Skinner5-May-05 13:20
MemberBeau Skinner5-May-05 13:20 
GeneralRe: Naming output files according to version/build numbers Pin
peterchen5-May-05 13:30
Memberpeterchen5-May-05 13:30 
GeneralRe: Naming output files according to version/build numbers Pin
Beau Skinner7-May-05 0:22
MemberBeau Skinner7-May-05 0:22 
GeneralRe: Naming output files according to version/build numbers Pin
peterchen7-May-05 2:13
Memberpeterchen7-May-05 2:13 
GeneralRe: Naming output files according to version/build numbers Pin
Beau Skinner7-May-05 13:58
MemberBeau Skinner7-May-05 13:58 
GeneralRe: Naming output files according to version/build numbers Pin
Beau Skinner7-May-05 0:04
MemberBeau Skinner7-May-05 0:04 
GeneralFormat differences... Pin
rbid27-Nov-04 0:50
Memberrbid27-Nov-04 0:50 
GeneralRe: Format differences... Pin
peterchen27-Nov-04 23:55
Memberpeterchen27-Nov-04 23:55 
GeneralRCStamp appends empty lines at the end of the target file Pin
Thomas Haase18-Mar-04 0:20
MemberThomas Haase18-Mar-04 0:20 
Generalfix Pin
peterchen16-Apr-04 15:05
Memberpeterchen16-Apr-04 15:05 
GeneralImprovement Pin
Anonymous17-Aug-02 0:14
MemberAnonymous17-Aug-02 0:14 
GeneralRe: Improvement Pin
Ddub8-Mar-03 16:25
MemberDdub8-Mar-03 16:25 
GeneralRe: Improvement Pin
Suhn11-Feb-06 10:40
MemberSuhn11-Feb-06 10:40 
GeneralRe: Improvement Pin
advance51218-Jun-09 4:21
Memberadvance51218-Jun-09 4:21 

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.