Version resources, part 1: Adding version information to an application
Introduction
Adding version information to an application is actually easier than most people think, and there are only 3 basic steps you have to worry about:
Create a version resource in a .RC file
Compile the .RC file into a .RES file with the MS resource compiler
Add the .RES file into the project as an external library
A .RC file is a text-only representation of a resource. An .RC file can contain a number of different resource definition statements including resources (bitmaps, cursors, fonts, icons), controls (radio buttons, icons, scrollbars, check boxes, combo boxes) and simple definition statements (menus, menu items, window classes, window styles)
A .RES file is a binary representation of the same information. An .RC file cannot be added to the application directly - instead, it has to be compiled into the .RES file by a resource compiler, and the .RES file is what is added to the application. Because CW handles all of the windows/menus/bitmaps for us you very rarely, if ever, need to manually define anything except a version resource in a .RC file.
1. Create a version resource
Of the 3 steps the first is probably the most difficult, because you don't know what a version resource looks like. The easiest way to create one is to open an existing application that does contain a version resource in a resource editor, such as Visual Studio or Resource Workshop, cut/paste the version resource into a new file and then change it to suit your needs
The full structure for a version resource is fully documented in MSDN, so I won't bother describing all of the fields here, suffice to say that there are a number of different fields that can define the file as being one of many different types. Examples are :
| Field | Denotes the file as being ... |
| File flags | Debug build, patched build, pre-release, private build or special build |
| OS | Suitable for Win16, Win32, WinNT/2000 or Win32s |
| File type | Executable, DLL, device driver, font, VXD or static library |
| File sub-type (depending on type) | Raster font, vector font, TrueType font, serial driver, network driver, printer driver etc etc |
The following example resource is for a 32-bit application.
#define VOS_NT_WINDOWS32 0x00040004L
#define VFT_APP 0x00000001L
1 VERSIONINFO
FILEVERSION 0, 0, 0, 0
PRODUCTVERSION 0, 0, 0, 0
FILEOS VOS_DOS_WINDOWS32
FILETYPE VFT_APP
{
BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "CompanyName", "Company name goes here\000"
VALUE "FileDescription", "File description goes here\000"
VALUE "FileVersion", "Version info goes here\000"
VALUE "InternalName", "Internal name goes here\000"
VALUE "LegalCopyright", "Copyright strng goes here - use \251 for copyright symbol\000"
VALUE "OriginalFilename", "Filename goes here\000"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 1033, 1252
}
}
The definitions for VFT_APP and VFP_NT_WINDOWS32 are taken from the WINVER.H file in the Platform SDK. This header file contains not only all the definitions you'll need to define a version resource with the special fields I mentioned earlier, but also the prototypes you'll need to check the version information once it's in a file.
When you set your version number into the version resource, you must take care to set the FILEVERSION and PRODUCTVERSION number fields as well as the FileVersion string. When you view the version information by right-clicking on the file, Windows 2000 uses the FILEVERSION number but Win9x uses the FileVersion string. If you fail to set all 3 fields your version information will not be correct under all operating systems.
2. Compile the .RC file into a .RES file
To compile the .RC file in the .RES file you need to use a resource compiler. There a couple of things to note, though.
The TopSpeed resource compiler (TSRC.EXE) that shipped with the TopSpeed Resource Kit (for JPI DOS-based languages, not the Clarion Resource Kit that was for CW) does not support version resources.
There are 2 different Microsoft compilers, one that generates ANSI .RES file and one that generates a Unicode .RES file.
3. Add the .RES file into the project
The last part is definately the easiest. If you are using a hand-coded project (.PR or .PRJ file) you can add the compiled .RES file into the application by editing the project file and adding the following line:
#pragma link(myfile.res)
If you are working on a .APP file using the project editor inside the IDE you simply add the .RES file to the "Library, object and resource files" section of the project.
Alternatives
If you don't fancy doing all this manually there are a couple of alternatives you can use.
Larry Sand has an open-source version information resource compiler available at Clarion Magazine. Larry's compiler only supports version resources and creates a .RES file directly from a CSV text file instead of a .RC file. You can download the compiler direct from the Open Source section at Clarion Magazine
You can use the freeware Locus Templates to add version information directly to an application. The templates create the .RES file directly without the need for a .RC file, but it does mean you have to change the information manually in each app every time you do a compile - not a nice job if you want to change the version number in multiple applications.
Back to the home page