获取文件版本号

function GetFileVersion(vFileName: string): string;
var
  Temp, InfoSize: Cardinal;
  FileData: Pointer;
  FileInfo: PVSFixedFileInfo;
begin
  Result := '';
  if not FileExists(vFileName) then Exit;

  InfoSize := GetFileVersionInfoSize(PChar(vFileName), Temp);
  if InfoSize  = 0 then Exit;       //没有版本号
  FileData := GetMemory(InfoSize);
  try
    if not GetFileVersionInfo(PChar(vFileName), 0, InfoSize, FileData) then Exit;
    if not VerQueryValue(FileData, '\', Pointer(FileInfo), Temp) then Exit;
    GV_VersionInfo.Ver1:= FileInfo.dwFileVersionMS div $10000;
    GV_VersionInfo.Ver2:= FileInfo.dwFileVersionMS mod $10000;
    GV_VersionInfo.Ver3:= FileInfo.dwFileVersionLS div $10000;
    GV_VersionInfo.Ver4:= FileInfo.dwFileVersionLS mod $10000;
    Result := Format('%d.%d.%d.%d',
      [FileInfo.dwFileVersionMS div $10000,
       FileInfo.dwFileVersionMS mod $10000,
       FileInfo.dwFileVersionLS div $10000,
       FileInfo.dwFileVersionLS mod $10000]);
  finally
    FreeMemory(FileData)
  end;
end;

你可能感兴趣的:(Delphi心得)