Click here to Skip to main content
15,879,326 members
Articles / Desktop Programming / MFC
Article

Auto Windows Resource (*.rc) version Editor

Rate me:
Please Sign up or sign in to vote.
4.33/5 (13 votes)
23 Jun 20033 min read 123.8K   2.2K   48   16
This freeware allows to edit a Windows Resources File (*.rc) and to produce a file named 'version.h' containing several string constants (#define). It can also synchronize a RC file and version.h with the Classbuilder Master Header File.

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

Image 2

  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


Written By
Web Developer
France France
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,)

Comments and Discussions

 
Generalrcversion.rc2 and rcversion.ico missing Pin
RichieB2B9-Jun-03 8:45
RichieB2B9-Jun-03 8:45 
Looks like they should be in a subdir "res" which is not in the zip file.

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.