Click here to Skip to main content
Click here to Skip to main content

Auto Windows Resource (*.rc) version Editor

By , 23 Jun 2003
 

Sample Image - rcversion_snapsho.png

Introduction

This freeware is inspired by a tool by Srinivas Vaithianathan hosted by CodeProject too: Versioning of executables at build time. I completely modified it and now there isn't any code remaining from it.

Since several years now, I'm using a great open source tool named ClassBuilder. This tool is provided by Jimmy Venema and can be found at SourceForge.

From Sourceforge project page:

ClassBuilder is a freeware CASE tool targeted at the C++ developer, running on Win95/98/NT. It lets you create, manipulate and navigate classes, class relations, class members and class methods at a high level of abstraction through a graphical user interface.

ClassBuilder generates two files for each class (one *.cpp and one *.h) and a Master Header File for the whole data model. The Master Header File includes all the classes' headers, defines the typedefs,... This file also contains some symbolic constants which are automatically updated when you generate the sources. According to a data model named model, the Master Header File model.h will contain:

#define MODEL_DATE      20030211
#define MODEL_TIME      193311
#define MODEL_VERSION   12

Each time you change the interface, ClassBuilder increments MODEL_VERSION and updates MODEL_DATE and MODEL_TIME.

Compiling the data model as executable or DLL

To use the data model, you should compile it as a static lib, an executable or a DLL. In case of exe or DLL, the Visual Studio generates a *.rc file. This file contains GUI definitions, icons, cursors, bitmaps... It should also contain the version information of the binary.

Here is the fragment of code in a Windows Resource File which describes the version information for RCVersion itself.

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1, 0, 0, 100
PRODUCTVERSION 1, 0, 0, 1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x9L
#else
 FILEFLAGS 0x8L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "Comments", "Modified by BZCToOn's"
            VALUE "CompanyName", "Syntheretix"
            VALUE "FileDescription", "rcversion MFC Application"
            VALUE "FileVersion", "1, 0, 0, 100"
            VALUE "InternalName", "rcversion"
            VALUE "LegalCopyright", "Copyleft (C) Bzc ToOn'S 2002"
            VALUE "OriginalFilename", "rcversion.EXE"
            VALUE "PrivateBuild", "RCVERSION-20030212_100"
            VALUE "ProductName", "rcversion Application"
            VALUE "ProductVersion", "1, 0, 0, 1"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

What RCVersion does?

RCVersion parses both the Master Header File and the Resources File. Next, according to the information contained in these two files, it generates a file named version.h and updates the Resources File.

Output: version.h

Here is the output file produced by RCVersion for itself.

// Generated by RCVersion 1.0.0.1 build RCVERSION-20030212_100 (20030213-020245)
// Copyleft (C) Bzc ToOn'S 2002
// Generated on 13/02/2003 02:02:46 from resource file rcversion.rc
#define __SNAPSHOT__        "20030213-020246"
#define __FILEVERSION__     "1.0.0.100"
#define __PRODUCTVERSION__  "1.0.0.1"
#define __COMPANY__         "Syntheretix"
#define __PRODUCT__         "rcversion Application"
#define __DESCRIPTION__     "rcversion MFC Application"
#define __PRIVATEBUILD__    "RCVERSION-20030212_100"
#define __COPYRIGHT__       "Copyleft (C) Bzc ToOn'S 2002"

// Master Header Values (ClassBuilder)!!
#define __CB_DATE__         "20030212"
#define __CB_TIME__         "190244"
#define __CB_VERSION__      "100"

// Do Not Modify !!

Command line execution

rcversion [-q] [-i input]
  -q   quiet: don't show the UI. Usefull for Custom Build Step in Visual Studio.
  -i   input: specify the input file. The input file could be *.rc or *.h.
              The filename without extension will be used as data model name.

How to use RCVersion with Visual Studio

  1. Add a file to the project: version.h
  2. Define Custom Build Step
    • Command Line: rcversion -q -i $(TargetName)
    • Description: RCVersion
    • Output: version.h
    • Dependencies: $(TargetName).h
  3. You can now put #include 'version.h' in $(TargetName).h or in stdafx.h.

Don't forget to put RCVERSION in path

or

To set Visual Studio executable path to the directory where RCVERSION is installed

Features

  • Version number extraction from Classbuilder Master Header File
  • RC File version information editor
  • version.h generation
  • Optional RC file update
  • Backup of your old version.h and RC files
  • Preview of version.h and RC files
  • Edition of version.h and RC files (through Notepad :-))
  • Non interactive execution

Bugs & limitation

I only tested RCVersion on my own projects. For me, it runs fine. I hope for you too ;-).

History

  • RCVERSION-20030212_100
    • First release
  • RCVERSION-20030214_200
    • version.h: Added #ifdef _DEBUG / #endif
    • version.h: better formatting
    • Added new field 'Symbols Prefix' to the symbolic constants
    • Added new command line option -p prefix to set the symbols prefix
    • Preview control is now a RichEdit one to support fixed width font

Fixed Bugs

  • RC File parsing: If a control ID contains one of the VERSIONINFO directive (FILEVERSION, PRODUCTVERSION), the whole line is replaced and the whole RC File is corrupted.

License

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

Réda BOUREBABA
Web Developer
France France
Member
I started programming when I was 12 years old. Since I learned some computer languages (C/C++, Perl, PHP, ASM(Z80, 68000, x86), UML ,SQL,...), some API (FLTK, QT, wxWindows, Win32, Direct3D, OpenGL and now MFC...).
Next, I worked as Web Programmer, as Network & Systems Admin (Scientific Calculators, Virtual Reality System, Solaris, SGI, W9X/NT/2K/XP,....).
Now I'm Computer Consultant from Network & Systems Administration and specific developments (PHP/MYSQL, Perl, C/C++/MFC,)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralProject missingmemberanubis_ex4 Oct '07 - 6:01 
There is a project called sertup_rcversion and VS was lookin for it. and surprise is missing. Do you forgot include the project ??
GeneralOne small bugmemberambarish_guntun14 Sep '04 - 1:33 
The min in the
#define __SNAPSHOT__         "20040914-160932"
is not changed. It is "09" always.
 
The format is: date-hhmmss; the "mm" part always remain "09". Am I missing something?
 
I am using Visual Studio 6.0
GeneralPre-Build Event instead of Custom Build StepmemberRichieB2B9 Jun '03 - 8:53 
Great tool. Exactly what I needed. Since it produces a file needed for your code (version.h) doesn't it make more sense to put it as a Pre-Build Event instead of a Custom Build Step?
 
Also.. since I use it to generate version.h from the .rc file, it is quite annoying that the .rc files gets recreated at the end. A switch to disable this would be nice. I'll make that switch myself once I get the thing to compile (see other post).
 
Thanks!
 
Richie
GeneralRe: Pre-Build Event instead of Custom Build StepmemberRéda BOUREBABA9 Jun '03 - 11:39 
Yes, you're right but this tool is used to synchronize 3 files :
- your_project.h
- your_project.rc
- version.h
 
if you change the master header file 'your_project.h' both 'your_project.rc' and 'version.h' will be recreated. So the it's better to maintains version information in the master header instead of in the '*.rc' file.

GeneralRe: Pre-Build Event instead of Custom Build StepmemberRichieB2B9 Jun '03 - 23:08 
I see, that makes sense actually. What are the keywords in "your_project.h" that I can use to drive the updates to your_project.rc and version.h?
 
Is it possible to disable the warning Visual Studio gives about "your_project.rc has been modified outside Visual Studio do you want to reload it?"
GeneralRe: Pre-Build Event instead of Custom Build StepmemberRéda BOUREBABA10 Jun '03 - 10:25 

From the online doc :"ClassBuilder generates two files for each class (one *.cpp and one *.h) and a Master Header File for the whole data model. The Master Header File includes all the classes headers, defines the typedefs,... This file also contains some symbolic constants which are automatically updated when you generates the sources. According a data model named 'model', the Master Header File 'model.h' will contains :
 
#define MODEL_DATE 20030211
#define MODEL_TIME 193311
#define MODEL_VERSION 12
 
Each time you changed the interface ClassBuilder increments MODEL_VERSION and updates MODEL_DATE and MODEL_TIME."
 

So in case of 'your_project.h'

#define YOUR_PROJECT_DATE 20030211
#define YOUR_PROJECT_TIME 193311
#define YOUR_PROJECT_VERSION 12
 

The Warning in visual studio occurs only when you change the master header file 'your_project.h'. To, solve it you could disable the external changes warning and make VS7 automatically reload the changed file.
 

Generalrcversion.rc2 and rcversion.ico missingmemberRichieB2B9 Jun '03 - 8:45 
Looks like they should be in a subdir "res" which is not in the zip file.
QuestionHow compile in Visual C++ 6memberPiccinano12 Feb '03 - 23:40 
Hi,
the project is for VC++ 7 but it miss the .sln file to convert it to VC++ 6.
 
Please to give the VC++ 6 users the opportuneness to compile the project.
 
Thanks.
AnswerRe: How compile in Visual C++ 6memberRéda BOUREBABA13 Feb '03 - 2:09 
I uploaded a new sources archive which contains the *.sln file.
General__SYMBOL__memberDalle12 Feb '03 - 21:09 
Symbols that start with two underscores are reserved by the compiler.
 
Good idea for an article though.

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 24 Jun 2003
Article Copyright 2003 by Réda BOUREBABA
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid