Delphi Base

WindSon

导航

读取软件的版本信息 GetFileVersionInfo

function GetBuildInfo(FileName: string; var V1, V2, V3, V4: Word): Boolean;
var
    VerInfoSize, VerValueSize, Dummy: DWORD;
    VerInfo: Pointer;
    VerValue: PVSFixedFileInfo;
begin
    if not FileExists(FileName) then
    begin
        result := false;
        exit;
    end;
    VerInfoSize := GetFileVersionInfoSize(PChar(FileName), Dummy);
    if VerInfoSize = 0 then
    begin
        result := false;
        exit;
    end;
    GetMem(VerInfo, VerInfoSize);
    if not GetFileVersionInfo(PChar(FileName), 0, VerInfoSize, VerInfo) then
    begin
        result := false;
        exit;
    end;
    VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
    with VerValue^ do
    begin
        V1 := dwFileVersionMS shr 16;
        V2 := dwFileVersionMS and $FFFF;
        V3 := dwFileVersionLS shr 16;
        V4 := dwFileVersionLS and $FFFF;
    end;
    FreeMem(VerInfo, VerInfoSize);
    result := true;
end;

 

posted on 2020-04-09 00:20  windsonvip  阅读(742)  评论(0编辑  收藏  举报