2016-08-21 62 views
1

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

但我不断收到错误

运行时错误(6:366) - 访问冲突在地址0042FD23。阅读地址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 '[email protected]{tmp}\MediaInfo.dll stdcall delayload'; 
function MediaInfo_Open(Handle: Cardinal; File__: PWideChar): Boolean; 
    external '[email protected]{tmp}\MediaInfo.dll stdcall delayload'; 
function MediaInfo_Get(Handle: Cardinal; StreamKind: Integer; StreamNumber: Integer; Parameter: PWideChar; KindOfInfo: Integer; KindOfSearch: Integer): PWideChar; 
    external '[email protected]{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); 

我预计该编译器的输出将是Width of the JPEG Image: 1920.

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

在此先感谢您的重要帮助。

+0

你从哪里获得这些针对'MediaInfo.DLL'的DLL调用?他们是从Delphi实例中获得的吗? – GTAVLover

+0

是@GTAVLover .........我认为他们很好.......你的建议也很好.......正是我想要的是通过'LoadStringFromFile '。:-) – Blueeyes789

回答

1

您可以使用带有Inno Setup Ansi或Unicode版本的MediaInfo Command Line Interface

用法示例:

[Files] 
Source: MediaInfo.exe; DestDir: {tmp}; Flags: Dontcopy 

[code] 
function InitializeSetup(): Boolean; 
var 
    ErrorCode: Integer; 
begin 
    ExtractTemporaryFile('MediaInfo.exe'); 
    ShellExec('Open', 'MediaInfo.exe', ExpandConstant('"YourFileName.mp4" --LogFile="YourFileName Prperties.log"'), ExpandConstant('{tmp}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode); 
    if SysErrorMessage(DLLGetLastError) = SysErrorMessage(0) then 
    Result := True; 
end; 

现在,导航到Inno Setup的临时目录使用运行(Windows键+ R)命令管理员,看看你的媒体信息的日志文件存在有其中包含有关文件中的信息你在命令中给出的。

2

我不认为你可以调用一个返回指向Inno Setup Pascal脚本的字符串(字符缓冲区)的函数。

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

  • 声明功能,如果它返回Cardinal;
  • 使用一些可用的函数,它接受一个指针并将其复制到另一个指针。声明源指针为Cardinal,目标指针为string。其中一个功能是StrCpyN
function MediaInfo_Get(
    Handle: Cardinal; StreamKind: Integer; StreamNumber: Integer; 
    Parameter: string; KindOfInfo: Integer; KindOfSearch: Integer): Cardinal; 
    external '[email protected]{tmp}\MediaInfo.dll stdcall delayload'; 

function StrCpyN(S1: string; S2: Cardinal; Max: Cardinal): Cardinal; 
    external '[email protected] 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创新安装。

+0

这也是一个不错的选择,但棘手和容易....... ;-) – GTAVLover

+0

这似乎有点难,我该如何声明'StrCpyN'? – Blueeyes789

+0

对不起,我忘了'StrCpyN'声明。现在添加。 –

相关问题