Translate

2013/01/09

取得所有檔案頪型的版本資訊方法

資料來源:DLL file version

function getFileVersionStr( const sgFileName : string ) : string;
var infoSize: DWORD;
var verBuf:   pointer;
var verSize:  UINT;
var wnd:      UINT;
var FixedFileInfo : PVSFixedFileInfo;
begin
  infoSize := GetFileVersioninfoSize(PChar(sgFileName), wnd);

  result := '';

  if infoSize <> 0 then
  begin
    GetMem(verBuf, infoSize);
    try
      if GetFileVersionInfo(PChar(sgFileName), wnd, infoSize, verBuf) then
      begin
        VerQueryValue(verBuf, '\', Pointer(FixedFileInfo), verSize);

        result := IntToStr(FixedFileInfo.dwFileVersionMS div $10000) + '.' +
                  IntToStr(FixedFileInfo.dwFileVersionMS and $0FFFF) + '.' +
                  IntToStr(FixedFileInfo.dwFileVersionLS div $10000) + '.' +
                  IntToStr(FixedFileInfo.dwFileVersionLS and $0FFFF);
      end;
    finally
      FreeMem(verBuf);
    end;
  end;
end;

function getFileVersionInt( const sgFileName : string ) : Integer;
var infoSize: DWORD;
var verBuf:   pointer;
var verSize:  UINT;
var wnd:      UINT;
var FixedFileInfo : PVSFixedFileInfo;
begin
  infoSize := GetFileVersioninfoSize(PChar(sgFileName), wnd);

  result := 0;

  if infoSize <> 0 then
  begin
    GetMem(verBuf, infoSize);
    try
      if GetFileVersionInfo(PChar(sgFileName), wnd, infoSize, verBuf) then
      begin
        VerQueryValue(verBuf, '\', Pointer(FixedFileInfo), verSize);

        result := StrToInt( IntToStr(FixedFileInfo.dwFileVersionMS div $10000) +
                  IntToStr(FixedFileInfo.dwFileVersionMS and $0FFFF) +
                  IntToStr(FixedFileInfo.dwFileVersionLS div $10000) +
                  IntToStr(FixedFileInfo.dwFileVersionLS and $0FFFF) );
      end;
    finally
      FreeMem(verBuf);
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowMessage(getFileVersionStr('C:\ABC.EXE'));
  ShowMessage(IntToStr(getFileVersionInt('D:\CDE.DLL')));
end;

沒有留言:

張貼留言

Delphi 自動化 JSON 格式相容性分析

Delphi 自動化產出的 JSON 格式一直被詬病著,因為它的 JSON 格式在起始處一定會強制寫入「Meta Data」,它看起來像是: "table":[["EmpNo",6,0,0,0,4,0,0,false,false,...