In order to understand the mechanics of our technique in the article, "A component for reading version information from a program file," you must be familiar with the way C++Builder works with component information. Let's quickly review version resources.
Figure A: Enter version information page in the Project Options dialog box.
At the bottom of the Version Info tab, you'll find a list of version keywords to which you can assign values. C++Builder automatically creates a set of predefined keywords--you should use these keywords if possible, but you can add your own keywords to this list, if you have the need.
DWORD unusedparam ;
DWORD versionsize = GetFileVersionInfoSize (
Application->ExeName.c_str (),
&unusedparam) ;
You
also use this function to determine whether your application actually contains
version information. The only important parameter to this function is the name
of the file.
The GetFileVersionInfo API function copies the version resource information to
a buffer so your program can access it:
if (versionsize != 0)
{
char *buffer = new char [versionsize] ;
bool status = GetFileVersionInfo (
Application>ExeName.c_str (),
unusedparam,
versionsize,
(void *) buffer) ;
}
\StringFileInfo\LLLLCCCC\KeyNamewhere KeyName is the keyword defined in the Project Options dialog box and LLLL and CCCC are hexadecimal representations of the language and character-set identifiers used. The language and character-set identifiers may seem like extra information, because C++Builder allows you to enter version information for only one language. However, a program can contain version information in multiple languages and character sets. If you have access to a full-featured Windows resource editor, you can create multi-language resource information.
The key value \VarFileInfo\Translation references a list of language translations contained in the version information. This fragment returns a pointer to an array containing information about each language contained in the version information:
UINT datasize ;
struct
{
unsigned short language ;
unsigned short character_set ;
} *translation ;
status = VerQueryValue(
buffer,
"\\VarFileInfo\\Translation",
(void **) &translation,
&datasize) ;
int translationcount
= datasize
/ sizeof (*translation)
The
full key for the FileVersion keyword would be
String key
= "\\StringFileInfo\\"
+ String::IntToHex (translation
[0].language, 4)
+ String::IntToHex (translation
[0].character_set, 4)
+ "FileVersion" ;
The
file version is returned like this:
char *version ;
UNIT versionsize
status = VerQueryValue(
buffer,
key.c_str (),
(void **) &translation,
&versionsize) ;