从 Dephi DLL 更新 Inno Setup 进度条

Updating Inno Setup progress bar from Dephi DLL

我需要你的帮助。我正在尝试从 Inno Setup (ANSI) 中用 Delphi 10 Seattle 编写的 DLL 调用函数。但我不明白是什么问题。如果我在 Delphi 中创建应用程序并从 DLL 调用此函数,它会完美运行!见代码清单:

Delphi DLL:

function Process(Pb: TProgressBar): Integer; stdcall;
var
  I: integer;
begin
  for I := 0 to 1000 do
  begin
    Pb.Position := I;
    Pb.Update;
    Sleep(10);
  end;
end;

Exports
  Process;

创新设置 (ANSI):

function Count(Progr: TNewProgressBar): integer; external 'Process@files:CallC.dll stdcall delayload';

procedure NewButton1Click(Sender: TObject);
begin
   Count(NewProgressBar1);
end;

调用后我得到访问冲突。但是,在我阅读的 dpr 文件中评论,ShareMem 写第一行,但效果为零。

请告诉我如何从 Delphi DLL 正确更新 Inno Setup 中的进度条。

您不能以这种方式调用对象方法。如果您使用与 Inno Setup 构建时使用的 Delphi 完全相同的版本,您可能很幸运能够使它正常工作,正如您对 Delphi 应用程序的测试所示。但它仍然是错误的和不可靠的,不要这样做。当你使用不同的Delphi版本时,进度条class在内存中的布局是不同的,因此"Access violation".


对于这个特定的任务,您只需使用进度条的句柄即可轻松完成:

function Process(Handle: THandle): Integer; 
var
 I: Integer;
begin
  SendMessage(Handle, PBM_SETRANGE, 0, 1000 shl 16);
  for I := 0 to 1000 do
  begin
    SendMessage(Handle, PBM_SETPOS, I, 0);   
    UpdateWindow(Handle);
    Sleep(10);
  end;
end;

在 Inno Setup 中,调用如下函数:

function Count(Handle: THandle): integer;
  external 'Process@files:CallC.dll stdcall delayload';

procedure NewButton1Click(Sender: TObject);
begin
  Count(NewProgressBar1.Handle);
end;

对于更高级的任务,您需要使用回调。

  • Using callback to display filenames from external decompression dll (Inno Setup)
  • Call C# DLL from Inno Setup with callback