【问题标题】:Get version info from EXE file crashing on Delphi 11 after applying November Patch从应用 11 月补丁后在 Delphi 11 上崩溃的 EXE 文件中获取版本信息
【发布时间】:2021-11-29 11:44:44
【问题描述】:

我正在使用下面的函数从当前的 EXE 文件中获取版本信息。

问题是,在应用 Delphi 11 的十一月补丁后,该函数开始使应用程序崩溃。

我的代码如下所示。崩溃的行是这样的:

VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);

这是错误,在此之后应用程序关闭。在补丁之前,同样的功能没有问题。也许是一个错误的更新?

  function TForm1.version : string;
  var
    VerInfoSize: DWord;
    VerInfo: Pointer;
    VerValueSize: DWord;
    VerValue: PVSFixedFileInfo;
    Dummy: DWord;
    sfilename: string;
  begin
    sfilename := paramstr(0);
    VerInfoSize := GetFileVersionInfoSize(pchar(sfilename), Dummy);
    GetMem(VerInfo, VerInfoSize);
    GetFileVersionInfo(pchar(sfilename), 0, VerInfoSize, VerInfo);
    VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
    with VerValue^ do
    begin
      Result := inttostr(dwFileVersionMS shr 16);
      Result := Result + '.' + inttostr(dwFileVersionMS and $FFFF);
      Result := Result + '.' + inttostr(dwFileVersionLS shr 16);
      Result := Result + '.' + inttostr(dwFileVersionLS and $FFFF);
    end;
    FreeMem(VerInfo, VerInfoSize);
  end;

【问题讨论】:

  • 你不做任何错误检查。所以也许这些 API 调用失败了。检查 API 函数的返回值是否有错误。文档告诉您如何指示错误。
  • 将大小传递给FreeMem 也很奇怪。你不应该那样做。
  • @DavidHeffernan 是正确的,可能的原因是缺乏错误检查。除此之外,你的确切代码适用于我修补的 Delphi 11。
  • 另一个问题..为什么你有这个功能作为TForm1类的一部分。它可以是独立的功能。
  • 问题的答案在检索版本信息时会进行错误检查:stackoverflow.com/questions/17279394/…

标签: delphi delphi-11-alexandria


【解决方案1】:

其实问题是EXE文件没有任何版本信息,产生了异常,我没有处理。

以下答案的代码有效:

GetFileVersionInfoSize And GetFileVersionInfo return nothing

【讨论】:

  • 这不准确。报告了一个错误,您的代码被忽略了,进而导致了 AV
  • 你链接到 Q,它有错误的代码。您应该链接到the A with the correct code。您仍然没有理解异常是因为代码错误而不是因为缺少 VERSIONINFO 而发生的。
  • @AmigoJack 好的,已编辑。
  • 编辑仍然出错。例外是因为您的代码不好,而不是因为缺少版本信息。问题是您的代码没有检查错误并错误地假设错误不会发生。
猜你喜欢
  • 2022-01-05
  • 1970-01-01
  • 1970-01-01
  • 2010-09-20
  • 2014-05-08
  • 2021-09-21
  • 1970-01-01
  • 2022-09-27
  • 2020-01-25
相关资源
最近更新 更多