0

I am a noob in coding trying to make an installer with Inno Setup.
Basically I am trying to merge two codes I found on this site: one for having a /VERYSILENT installation, and another one for quitting the setup if a registry key is not found.
I already know I can't have two InitializeSetup functions, and if I got it right, I must be merging them using event attributes.
I already tried merging the two functions using only one "function InitializeSetup" in various ways, but usually only one code of the two works, the other seems invisible.
I tried also using the event attribute command, but I don't know how to properly use it.

This is my initial code with the two InitializeSetup functions:

#ifdef UNICODE
 #define AW "W"
#else
 #define AW "A"
#endif
type
 HINSTANCE = THandle;
function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string;
 lpParameters: string; lpDirectory: string; nShowCmd: Integer): HINSTANCE;
 external 'ShellExecute{#AW}@shell32.dll stdcall';
//First one
function InitializeSetup: Boolean;
begin
 Result := WizardSilent;
 if not Result then
 begin
  if ShellExecute(0, '', ExpandConstant('{srcexe}'), '/VERYSILENT', '',
   SW_SHOW) <= 32
  then
   Result := True;
 end;
end;
//Second one
function InitializeSetup: Boolean;
begin
 Result := True;
 if not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion... etc. etc.') then
 begin
  Result := False;
 end;
end;

Thanks in advance to whoever can help me.

EDIT

This is the code with the event attributes features that I put together from the example in the link Martin Prikryl gived me:

#ifdef UNICODE
 #define AW "W"
#else
 #define AW "A"
#endif
type
 HINSTANCE = THandle;
function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string;
 lpParameters: string; lpDirectory: string; nShowCmd: Integer): HINSTANCE;
 external 'ShellExecute{#AW}@shell32.dll stdcall';
<event('InitializeSetup')>
function InitializeSetup1: Boolean;
begin
 Result := WizardSilent;
 if not Result then
 begin
  if ShellExecute(0, '', ExpandConstant('{srcexe}'), '/VERYSILENT', '',
   SW_SHOW) <= 32
  then
   Result := True;
 end;
end;
<event('InitializeSetup')>
function InitializeSetup2: Boolean;
begin
 Result := True;
 if not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion... etc. etc.') then
 begin
  Result := False;
 end;
end;

Seems it's working now.

  • You actually can have two/multiple `InitializeSetup` functions in Inno Setup 6. See https://stackoverflow.com/q/40512631/850848 – Martin Prikryl Mar 14 '21 at 17:51
  • In the question you linked they are talking about events. Unfortunately I have already tried it, but I don't know how to use them. There isn't a clear example, and it's confusing to me. The thing I don't understand the most is what the "Log('InitializeWizard called');" is supposed to be. –  Mar 14 '21 at 18:27
  • I do not understand your comment. The `InitializeSetup` **is an event**. The "Inno Setup 6" section of my answer shows very clear example how to add two implementation of one event function. I've edited the answer lead, as it was bit obsolete. – Martin Prikryl Mar 14 '21 at 18:31
  • Sorry if I haven't been clear enough, I don't speak english very well. I tried to be more specific editing the main post. –  Mar 14 '21 at 20:59
  • I'm not sure what part of that wouldn't be clear. `Log()` writes to the installation log if logging is enabled. `Log("InitializeWizard called")` writes a line to the installation log that says "InitializeWizard called". – Ken White Mar 14 '21 at 23:32
  • Why are you trying to implement the old-style solution, instead of using the Inno Setup 6 `` tag? And even if you are stuck with Inno Setup 5 for some reason, my answer links another question that explicitly deals with the `InitializeSetup` function: [Inno Setup - Merging implementations of event functions that return boolean (like InitializeSetup)](https://stackoverflow.com/q/41464764/850848). – Martin Prikryl Mar 15 '21 at 06:51
  • I am trying the old-style solution simply because I have a very very basic knowledge of coding in general and I don't know how to implement the Inno Setup 6 section of your answer in the correct way. What it seems obvious and clear to you all, is not to me. I have edited the main post where I have tried with the event attributes feature but I don't how to write it or how it works. Can you help me? –  Mar 15 '21 at 22:29
  • My answer shows that the signature of the functions must be still the same, so `function ...(): Boolean;`. Not `procedure ...;`. – Martin Prikryl Mar 16 '21 at 08:34
  • Thank you very much for your patience, now that I understand how implement it, it seems to work without errors. Thank you once again. –  Mar 16 '21 at 21:07

0 Answers0