[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Get DLL Version Information, Specifically companyname

Posted on 2008-02-02
3
Medium Priority
?
1,415 Views
Last Modified: 2012-05-05
I'm basically trying to get the company name in dll's. Anyone know of a way other than VerQueryValue(). Iit wasn't returning it yet I know that the Company Name is filled.
0
Comment
Question by:ThievingSix
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
RickJ earned 2000 total points
ID: 20806603
I picked up this unit a while ago, (I installed as component). It seems to work fine, and is fairly straight forward.
I know you said "other than VerQueryValue(), but this uses it and works fine, maybe test and see how it goes.
Let me know.
unit CEVersionInfo;
 
interface
 
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
 
type
  TLangAndCP = record
    wLanguage : word;
    wCodePage : word;
    end;
  PLangAndCP = ^TLangAndCP;
 
  TCEVersionInfo = class(TComponent)
  private
    { Private declarations }
    FCompanyName      : string;
    FFileDescription  : string;
    FFileVersion      : string;
    FInternalname     : string;
    FLegalCopyright   : string;
    FLegalTradeMarks  : string;
    FOriginalFilename : string;
    FProductName      : string;
    FProductVersion   : string;
    FComments         : string;
    FMajorVersion     : string;
    FMinorVersion     : string;
    FRelease          : string;
    FBuild            : string;
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;
    destructor  Destroy; override;
  published
    { Published declarations }
    property CompanyName      : string read FCompanyName write FCompanyName stored False;
    property FileDescription  : string read FFileDescription write FFileDescription stored False;
    property FileVersion      : string read FFileVersion write FFileVersion stored False;
    property Internalname     : string read FInternalname write FInternalname stored False;
    property LegalCopyright   : string read FLegalCopyright write FLegalCopyright stored False;
    property LegalTradeMarks  : string read FLegalTradeMarks write FLegalTradeMarks stored False;
    property OriginalFilename : string read FOriginalFilename write FOriginalFilename stored False;
    property ProductName      : string read FProductName write FProductName stored False;
    property ProductVersion   : string read FProductVersion write FProductVersion stored False;
    property Comments         : string read FComments write FComments stored False;
    property MajorVersion     : string read FMajorVersion write FMajorVersion stored False;
    property MinorVersion     : string read FMinorVersion write FMinorVersion stored False;
    property Release          : string read FRelease write FRelease stored False;
    property Build            : string read FBuild write FBuild stored False;
 
    procedure GetInfo(FName : string);
  end;
 
const
  InfoNum = 10;
  InfoStr : array [1..InfoNum] of String = ('CompanyName', 'FileDescription',
  'FileVersion', 'InternalName', 'LegalCopyright', 'LegalTradeMarks',
  'OriginalFilename', 'ProductName', 'ProductVersion', 'Comments');
 
 
procedure Register;
 
implementation
 
procedure Register;
begin
  RegisterComponents('CESystem', [TCEVersionInfo]);
end;
 
constructor TCEVersionInfo.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  GetInfo(ParamStr(0));
end;
 
destructor TCEVersionInfo.Destroy;
begin
  inherited Destroy;
end;
 
procedure TCEVersionInfo.GetInfo(FName: string);
var
  N         : integer;
  ZValue    : cardinal;
  Buf       : PChar;
  Lang      : PLangAndCP;
  LangLen   : cardinal;
  SubBlock  : string;
  Value     : PChar;
  Len       : cardinal;
  S         : string;
  PointPos  : integer;
begin
  N:=GetFileVersionInfoSize(PChar(FName),ZValue);
  if N>0 then begin
    Buf:=AllocMem(N);
    GetFileVersionInfo(PChar(FName),0,N,Buf);
    VerQueryValue(Buf,PChar('\\VarFileInfo\\Translation'),Pointer(Lang),LangLen);
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[1],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FCompanyName:=string(Value);
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[2],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FFileDescription:=Value;
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[3],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FFileVersion:=Value;
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[4],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FInternalName:=Value;
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[5],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FLegalCopyright:=Value;
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[6],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FLegalTradeMarks:=Value;
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[7],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FOriginalFilename:=Value;
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[8],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FProductName:=Value;
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[9],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FProductVersion:=Value;
 
    SubBlock:=Format('\\StringFileInfo\\%.4x%.4x\\'+InfoStr[10],[Lang^.wLanguage,Lang^.wCodePage]);
    VerQueryValue(Buf,PChar(SubBlock),Pointer(Value),Len);
    FComments:=Value;
 
    if FFileVersion<>'' then begin
      PointPos:=Pos('.',FFileVersion);
      if PointPos<>0 then begin
        FMajorVersion:=Copy(FFileVersion,1,PointPos-1);
        S:=Copy(FileVersion,PointPos+1,Length(FFileVersion)-PointPos);
        PointPos:=Pos('.',S);
        FMinorVersion:=Copy(S,1,PointPos-1);
        S:=Copy(S,PointPos+1,Length(S)-PointPos);
        PointPos:=Pos('.',S);
        FRelease:=Copy(S,1,PointPos-1);
        FBuild:=Copy(S,PointPos+1,Length(S)-PointPos);
      end
      else begin
        PointPos:=Pos(',',FFileVersion);
        if PointPos<>0 then begin
          FMajorVersion:=Copy(FFileVersion,1,PointPos-1);
          S:=Copy(FileVersion,PointPos+1,Length(FFileVersion)-PointPos);
          PointPos:=Pos(',',S);
          FMinorVersion:=Copy(S,1,PointPos-1);
          S:=Copy(S,PointPos+1,Length(S)-PointPos);
          PointPos:=Pos(',',S);
          FRelease:=Copy(S,1,PointPos-1);
          FBuild:=Copy(S,PointPos+1,Length(S)-PointPos);
        end
        else begin
          FMajorVersion :='<info not available>';
          FMinorVersion :='<info not available>';
          FRelease      :='<info not available>';
          FBuild        :='<info not available>';
        end;
      end;
    end
    else begin
      FMajorVersion :='<info not available>';
      FMinorVersion :='<info not available>';
      FRelease      :='<info not available>';
      FBuild        :='<info not available>';
    end;
 
    FreeMem(Buf,N);
  end
  else begin
    FCompanyname      :='<info not available>';
    FFileDescription  :='<info not available>';
    FFileVersion      :='<info not available>';
    FInternalname     :='<info not available>';
    FLegalCopyright   :='<info not available>';
    FLegalTradeMarks  :='<info not available>';
    FOriginalFilename :='<info not available>';
    FProductName      :='<info not available>';
    FProductVersion   :='<info not available>';
    FComments         :='<info not available>';
    FMajorVersion     :='<info not available>';
    FMinorVersion     :='<info not available>';
    FRelease          :='<info not available>';
    FBuild            :='<info not available>';
  end;
end;
 
 
end.

Open in new window

0
 
LVL 13

Author Comment

by:ThievingSix
ID: 20807191
Well for some reason this worked perfectly, thanks.
0
 
LVL 8

Expert Comment

by:RickJ
ID: 20807777
Thanks. Gald I could help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question