Saturday, November 10, 2012

Working with version information at C++ Builder

From: http://bcbjournal.org/articles/vol3/9901/Working_with_version_information.htm?PHPSESSID=eb3eea609943c3d1bb8294288b945696


January 1999

Working with version information

by John M. MianoIn 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.

Creating version resources

In C++Builder, you set the version information for a program on the Version Info tab in the Project Options dialog box, as shown in Figure A. You must check the Include Version Information In Project check box in order to write the version resources to the executable file.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.

Reading version information

The GetFileVersionInfoSize Windows API function returns the number of bytes of version information stored in the image:
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) ;
}

Getting the language information

To extract individual items from the version information, you use the VerQueryValue API function. A unique string key identifies each version-information item. The format of this key string is
\StringFileInfo\LLLLCCCC\KeyName

where 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) ;


No comments:

Post a Comment

[Qt] 執行檔需要哪些 Dll?

 1. 使用 Qt  的 windeployqt.exe 工具 (在 C:\Qt\Qt5.14.1\5.14.1\msvc2017\bin\)。   a. 把執行檔 myProgram.exe 放在某個資料夾。   b. 在檔案總管這個資料夾按 Shift 和滑鼠右鍵,開啟 Po...