Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnZip files after install with InnoUnzip - Error "Invalid prototype"

unpacker I found what I was looking for, he should unpack the files after installation This is InnoUnzip.ZIP

My installer folder looks like this:

enter image description here

My code:

[Setup]
AppName=My Program
AppVersion=1.0
DefaultDirName={pf}\My Program
DisableProgramGroupPage=yes
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source: "unzipper.dll"; Flags: dontcopy
Source: "MyProg.exe"; DestDir: "{app}"
Source: "Somefile.zip"; DestDir: "{app}"; AfterInstall: ExtractMe('{app}\Somefile.zip', '{app}');

[Icons]
Name: "{commonprograms}\My Program"; Filename: "{app}\MyProg.exe"
Name: "{commondesktop}\My Program"; Filename: "{app}\MyProg.exe"

[Code]
procedure unzip(src, target: AnsiString);
external 'unzip@files:unzipper.dll stdcall delayload';

procedure ExtractMe(src, target : AnsiString); - ERROR HERE!!!!!
begin
  unzip(ExpandConstant(src), ExpandConstant(target));
end;

Text error: Invalid prototype for "Extract Me"

like image 375
michal3210 Avatar asked Mar 16 '23 12:03

michal3210


2 Answers

Following up TLama's point about the redundancy of the DLL: the same effect can be achieved simply by coding UnZip() directly within the Inno Setup script.

const
  SHCONTCH_NOPROGRESSBOX = 4;
  SHCONTCH_RESPONDYESTOALL = 16;

procedure Unzip(ZipFile, TargetFolder: String); 
var
  ShellObj, SrcFile, DestFolder: Variant;
begin
  ShellObj := CreateOleObject('Shell.Application');
  SrcFile := ShellObj.NameSpace(ZipFile);
  DestFolder := ShellObj.NameSpace(TargetFolder);
  DestFolder.CopyHere(SrcFile.Items, SHCONTCH_NOPROGRESSBOX or SHCONTCH_RESPONDYESTOALL)
end;

procedure ExtractMe(src, target : String); 
begin
  // Add extra application code here, then:
  Unzip(ExpandConstant(src), ExpandConstant(target));
end;

The Inno Setup script code is more or less the same as the DLL's... only a bit shorter.

Be aware that if Zip or Destination folder don't exist, the NameSpace() method calls return a Null, the CopyHere() fails, and the user sees a rude and baffling dialog - so best to check before calling.

like image 56
willw Avatar answered Apr 27 '23 13:04

willw


Change the parameter type AnsiString to String.

like image 38
spqpad Avatar answered Apr 27 '23 12:04

spqpad