Recuperando informações sobre a versão e o Build do Executável
A função VerQueryValue retorna as informações correntes no “version-information” resorce. No Delphi, no menu “Project/Options” (Shif + Ctrl + F11), você define várias configurações sobre o seu projeto. As definições sobre a versão do seu programa é definida na aba “Version Info”, basta você marcar a opção para incluir informação sobre a versão no projeto (Includ version infomation in projetct).

Essa função deve trabalhar em conjunto com a GetFileInformationInfo, pois esta última é quem recupera propriamente o valor desejado do “version-information”.
Todas as duas funções são chamadas a API do sistema operacional Windows. No Delphi 7 elas estão definidas na unit “Windows”.
Todas as duas funções são chamadas a API do sistema operacional Windows. No Delphi 7 elas estão definidas na unit “Windows”.
Analisado a Função:
function VerQueryValue; external version name ‘VerQueryValueA’;
function VerQueryValue(
const LPVOID pBlock, // Endereço do buffer para o “version resource”.
LPTSTR lpSubBlock, // Endereço para o valor a ser recuperado
LPVOID *lplpBuffer, // Ponteiro para o endereço do buffer onde esta armazenado as informações.
PUINT puLen // Endereço do versio-value length buffer
);
Parameters
pBlock
Points to the buffer containing the version-information resource
returned by GetFileVersionInfo.
lpSubBlock
Points to a zero-terminated string specifying which version-information value to
retrieve. The string consists of names separated by backslashes (\) and can have
one of the following forms:
Form Description
\ Specifies the root block. The function retrieves a pointer to the
VS_FIXEDFILEINFO structure for the version-information resource.
\VarFileInfo\Translation Specifies the translation table in the
variable information structure. The function retrieves a pointer to an
array of language and character-set identifiers. An application uses
these identifiers to create the name of a language-specific structure in
the version-information resource.
\StringFileInfo\lang-charset\string-name
Specifies a value in a language-specific structure.
The lang-charset name is a concatenation of a language and character-set
identifier pair found in the translation table for the resource.
The lang-charset name must be specified as a hexadecimal string.
The string-name name is one of the predefined strings described in the
following Remarks section.
lplpBuffer
Points to a buffer that receives a pointer to the version-information value.
puLen
Points to a buffer that receives the length, in characters, of the
version-information value. (retirado de Win32 Programming Techniques)
Existem em vários exemplos sobre o uso dessa função na web, basta “googar” buscando bor “VerQueryValue” e retornará uma série de links. Vou colocar um exemplo simples aqui somente a título de documentação:
Adicione num Form dois componentes “TLabel” (Label1 e Label2)e um TListBox (ListBox1). No Evento "OnCreate" do From1 digite como exemplificado abaixo:
procedure TForm1.FormCreate(Sender: TObject); const AExa = '041604E4'; AFileInfo = '\StringFileInfo\'; var ApplicationExeName: String; ReservedSpace, VLength: Cardinal; MyBuff: PChar; VersionBuild, CommentBuild: String; begin ApplicationExeName := Application.ExeName; ListBox1.Items.Add(ApplicationExeName); ReservedSpace := GetFileVersionInfoSize(PChar(ApplicationExeName), ReservedSpace); ListBox1.Items.Add(Format(ApplicationExeName + '- Tamanho Alocado = %d', [ReservedSpace])); if (ReservedSpace > 0) then begin MyBuff := AllocMem(ReservedSpace); GetFileVersionInfo(PChar(ApplicationExeName),0, ReservedSpace, MyBuff); VerQueryValue(MyBuff, PChar(AFileInfo + AExa+ '\FileVersion'), Pointer(VersionBuild), VLength); Label1.Caption := VersionBuild; VerQueryValue(MyBuff, PChar(AFileInfo + AExa+ '\Comments'), Pointer(CommentBuild), VLength); Label2.Caption := CommentBuild; end; end;
Antes de executar o programa no menu “Project” ▶ Options” (Alt, P, O), na aba “Version Info”.no Grid de valores chaves, na linha Comments adicione um comentário. Conforme exemplificado abaixo.

Execute o programa e teste ...

Nenhum comentário:
Postar um comentário