inno-setup - 在 Inno Setup Pascal 脚本中使用 MediaInfo 库获取图像文件信息

标签 inno-setup pascalscript mediainfo

两天多以来,我一直在尝试在 Pascal 脚本中使用 MediaInfo.DLL 获取 JPEG 图像和 MP4 视频文件信息。

但我不断收到错误

Runtime Error (at 6:366) - Access Violation at address 0042FD23. Read of address 8065241E.'

错误主要指向(6:366)。

当尝试使用 MediaInfo.DLL 获取媒体信息时,我无法想象是什么问题导致了此异常。

我添加到脚本中的代码:

[Files]
Source: Lamborghini_Aventador.jpg; DestDir: {tmp}; Flags: dontcopy
Source: MediaInfo.dll; DestDir: {tmp}; Flags: dontcopy

[Code]
#ifdef UNICODE
type
  PWideChar = WideString;
#endif

const
  StreamKind_Image = 5;
  InfoKind_Text = 1;

function MediaInfo_New: Cardinal;
  external 'MediaInfo_New@{tmp}\MediaInfo.dll stdcall delayload';
function MediaInfo_Open(Handle: Cardinal; File__: PWideChar): Boolean;
  external 'MediaInfo_Open@{tmp}\MediaInfo.dll stdcall delayload';
function MediaInfo_Get(Handle: Cardinal; StreamKind: Integer; StreamNumber: Integer; Parameter: PWideChar; KindOfInfo: Integer; KindOfSearch: Integer): PWideChar;
  external 'MediaInfo_Get@{tmp}\MediaInfo.dll stdcall delayload';

procedure RetrieveImageInformation;
var
  IHandle: Cardinal;
  Width: PWideChar;
begin
  ExtractTemporaryFile('Lamborghini_Aventador.jpg');
  ExtractTemporaryFile('MediaInfo.dll');
  IHandle := MediaInfo_New();
  MediaInfo_Open(IHandle, PWideChar(ExpandConstant('{tmp}\Lamborghini_Aventador.jpg')));
  Width := MediaInfo_Get(IHandle, StreamKind_Image, 0, 'Width', InfoKind_Text, 0);
  Log('Width of the JPEG Image: ' + PWideChar(Width) + '.');
end;

生成异常的行是:

Width := MediaInfo_Get(IHandle, StreamKind_Image, 0, 'Width', InfoKind_Text, 0);

我预计编译器输出将为JPEG 图像的宽度:1920。

我使用最新版本的 Unicode Inno Setup Compiler (5.5.9 - U)

预先感谢您的重要帮助。

最佳答案

我认为您不能调用从 Inno Setup Pascal 脚本返回指向字符串(字符缓冲区)的指针的函数。

但是你可以像这样破解它:

  • 将函数声明为返回 Cardinal
  • 使用一些可用的函数来获取一个指针并将其复制到另一个指针。将源指针声明为Cardinal,将目标指针声明为stringStrCpyN 就是这样一个函数。 .
function MediaInfo_Get(
  Handle: Cardinal; StreamKind: Integer; StreamNumber: Integer;
  Parameter: string; KindOfInfo: Integer; KindOfSearch: Integer): Cardinal;
  external 'MediaInfo_Get@{tmp}\MediaInfo.dll stdcall delayload';

function StrCpyN(S1: string; S2: Cardinal; Max: Cardinal): Cardinal;
  external '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b785f59685b52657c6b5843475c4a5b42054f4747" rel="noreferrer noopener nofollow">[email protected]</a> stdcall';
var
  P: Cardinal;
  S: string;
begin
  P := MediaInfo_Get(IHandle, StreamKind_Image, 0, 'Width', InfoKind_Text, InfoKind_Name);
  S := StringOfChar(' ', 1024);
  StrCpyN(S, P, Length(S) - 1);
  S := Trim(S);
  ...
end;

代码需要Unicode Inno Setup (Inno Setpu 6 以来的唯一版本)。

关于inno-setup - 在 Inno Setup Pascal 脚本中使用 MediaInfo 库获取图像文件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39064058/

相关文章:

windows - WinHttpRequest.5.1 是适用于 Windows 11 的良好 API 还是需要 Iexplorer?

inno-setup - 在 Inno Setup 脚本中将一个很长的字符串参数拆分为多行

inno-setup - 安装到 USB 驱动器根目录时出现 Inno Setup 错误 : "You must enter a full path with drive letter"

mysql - 使用 Inno Setup 运行 .sql 文件

Inno Setup 中的视频文件,相对路径作为初始屏幕

installation - Inno Setup 中的函数指针

inno-setup - 使用命令行参数抑制 Inno Setup 任务

使用 MediaInfo.dll 的 C# 发布应用程序

audio - 检查视频中嵌入的音频是否为 Ambisonic 的最佳方法是什么?

c# - 无法在 DLL 'MediaInfo_New' 中找到名为 'MediaInfo.dll' 的入口点