소스 검색

Doc and demo CreateCallback and also some other tweaks.

Martijn Laan 6 년 전
부모
커밋
2a0b730cf1
4개의 변경된 파일60개의 추가작업 그리고 21개의 파일을 삭제
  1. 32 20
      Examples/CodeDll.iss
  2. 4 0
      ISHelp/isetup.xml
  3. 22 0
      ISHelp/isxfunc.xml
  4. 2 1
      whatsnew.htm

+ 32 - 20
Examples/CodeDll.iss

@@ -1,11 +1,12 @@
 ; -- CodeDll.iss --
 ; -- CodeDll.iss --
 ;
 ;
-; This script shows how to call DLL functions at runtime from a [Code] section.
+; This script shows how to call functions in external DLLs (like Windows API functions)
+; at runtime and how to perform direct callbacks from these functions to functions
+; in the script.
 
 
 [Setup]
 [Setup]
 AppName=My Program
 AppName=My Program
 AppVersion=1.5
 AppVersion=1.5
-DisableWelcomePage=no
 DefaultDirName={autopf}\My Program
 DefaultDirName={autopf}\My Program
 DisableProgramGroupPage=yes
 DisableProgramGroupPage=yes
 UninstallDisplayIcon={app}\MyProg.exe
 UninstallDisplayIcon={app}\MyProg.exe
@@ -23,26 +24,18 @@ Source: "MyDll.dll"; DestDir: "{app}"
 const
 const
   MB_ICONINFORMATION = $40;
   MB_ICONINFORMATION = $40;
 
 
-//importing an ANSI Windows API function
-function MessageBox(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal): Integer;
-external 'MessageBoxA@user32.dll stdcall';
+// Importing a Unicode Windows API function
+function MessageBox(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
+external 'MessageBoxW@user32.dll stdcall';
 
 
-//importing a Windows API function, automatically choosing ANSI or Unicode (requires ISPP)
-//function MessageBox(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
-//#ifdef UNICODE
-//external '[email protected] stdcall';
-//#else
-//external '[email protected] stdcall';
-//#endif
-
-//importing an ANSI custom DLL function, first for Setup, then for uninstall
+// Importing an ANSI custom DLL function, first for Setup, then for uninstall
 procedure MyDllFuncSetup(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
 procedure MyDllFuncSetup(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
 external 'MyDllFunc@files:MyDll.dll stdcall setuponly';
 external 'MyDllFunc@files:MyDll.dll stdcall setuponly';
 
 
 procedure MyDllFuncUninstall(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
 procedure MyDllFuncUninstall(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
 external 'MyDllFunc@{app}\MyDll.dll stdcall uninstallonly';
 external 'MyDllFunc@{app}\MyDll.dll stdcall uninstallonly';
 
 
-//importing an ANSI function for a DLL which might not exist at runtime
+// Importing an ANSI function for a DLL which might not exist at runtime
 procedure DelayLoadedFunc(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
 procedure DelayLoadedFunc(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
 external '[email protected] stdcall delayload';
 external '[email protected] stdcall delayload';
 
 
@@ -50,7 +43,7 @@ function NextButtonClick(CurPage: Integer): Boolean;
 var
 var
   hWnd: Integer;
   hWnd: Integer;
 begin
 begin
-  if CurPage = wpWelcome then begin
+  if CurPage = wpSelectDir then begin
     hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
     hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
 
 
     MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
     MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
@@ -58,10 +51,10 @@ begin
     MyDllFuncSetup(hWnd, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
     MyDllFuncSetup(hWnd, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
 
 
     try
     try
-      //if this DLL does not exist (it shouldn't), an exception will be raised
+      // If this DLL does not exist (it shouldn't), an exception will be raised
       DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
       DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
     except
     except
-      //handle missing dll here
+      // <Handle missing dll here>
     end;
     end;
   end;
   end;
   Result := True;
   Result := True;
@@ -70,8 +63,7 @@ end;
 procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
 procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
 begin
 begin
   // Call our function just before the actual uninstall process begins
   // Call our function just before the actual uninstall process begins
-  if CurUninstallStep = usUninstall then
-  begin
+  if CurUninstallStep = usUninstall then begin
     MyDllFuncUninstall(0, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
     MyDllFuncUninstall(0, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
     
     
     // Now that we're finished with it, unload MyDll.dll from memory.
     // Now that we're finished with it, unload MyDll.dll from memory.
@@ -79,3 +71,23 @@ begin
     UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
     UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
   end;
   end;
 end;
 end;
+
+// The following shows how to use callbacks
+
+function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: Longword): Longword;
+external '[email protected] stdcall';
+
+var
+  TimerCount: Integer;
+
+procedure MyTimerProc(Arg1, Arg2, Arg3, Arg4: Longword);
+begin
+  Inc(TimerCount);
+  WizardForm.BeveledLabel.Caption := ' Timer! ' + IntToStr(TimerCount);
+  WizardForm.BeveledLabel.Visible := True;
+end;
+
+procedure InitializeWizard;
+begin
+  SetTimer(0, 0, 1000, CreateCallback(@MyTimerProc));
+end;

+ 4 - 0
ISHelp/isetup.xml

@@ -3615,6 +3615,10 @@ Keep the default set of selected tasks, but deselect the "desktopicon" task:<br/
 
 
 <li>Evgeny Karpov of RemObjects Software: Initial work on Unicode support.</li>
 <li>Evgeny Karpov of RemObjects Software: Initial work on Unicode support.</li>
 
 
+<li>DRON: Code for the improved image stretching (5.6.0).</li>
+
+<li>Sherlock Software: Most of the code for the <tt>CreateCallback</tt> support function (6.0).</li>
+
 </ul>
 </ul>
 
 
 </body>
 </body>

+ 22 - 0
ISHelp/isxfunc.xml

@@ -728,6 +728,28 @@ end;</pre></example>
       </function>
       </function>
     </subcategory>
     </subcategory>
     <subcategory>
     <subcategory>
+      <function>
+        <name>CreateCallback</name>
+        <prototype>function CreateCallback(Method: AnyMethod): Longword;</prototype>
+        <description><p>Allows you to perform direct callbacks from functions in external DLLs (like Windows API functions) to functions in your script.</p></description>
+        <example><pre>function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: Longword): Longword;
+external '[email protected] stdcall';
+
+var
+  TimerCount: Integer;
+
+procedure MyTimerProc(Arg1, Arg2, Arg3, Arg4: Longword);
+begin
+  Inc(TimerCount);
+  WizardForm.BeveledLabel.Caption := ' Timer! ' + IntToStr(TimerCount);
+  WizardForm.BeveledLabel.Visible := True;
+end;
+
+procedure InitializeWizard;
+begin
+  SetTimer(0, 0, 1000, CreateCallback(@MyTimerProc));
+end;</pre></example>
+      </function>
       <function>
       <function>
         <name>UnloadDLL</name>
         <name>UnloadDLL</name>
         <prototype>procedure UnloadDLL(Filename: String);</prototype>
         <prototype>procedure UnloadDLL(Filename: String);</prototype>

+ 2 - 1
whatsnew.htm

@@ -95,6 +95,7 @@ For conditions of distribution and use, see <a href="http://www.jrsoftware.org/f
   <ul>
   <ul>
     <li>Using event attributes it is now possible to have multiple implementations of the same event function in your script. This is especially useful in included scripts implementing an event function to avoid conflicts with the main script. See the help file for more information and the <i>CodeExample1.iss</i> example script for an example.</li>
     <li>Using event attributes it is now possible to have multiple implementations of the same event function in your script. This is especially useful in included scripts implementing an event function to avoid conflicts with the main script. See the help file for more information and the <i>CodeExample1.iss</i> example script for an example.</li>
     <li>Added new <tt>TaskDialogMsgBox</tt> and <tt>SuppressibleTaskDialogMsgBox</tt> support functions which display a task dialog if supported by the system and a regular message box otherwise (<a href="https://i.imgur.com/hU4RQP2.png">example</a>). See the help file for more information and the <i>CodeClasses.iss</i> example script for an example.</li>
     <li>Added new <tt>TaskDialogMsgBox</tt> and <tt>SuppressibleTaskDialogMsgBox</tt> support functions which display a task dialog if supported by the system and a regular message box otherwise (<a href="https://i.imgur.com/hU4RQP2.png">example</a>). See the help file for more information and the <i>CodeClasses.iss</i> example script for an example.</li>
+    <li>Added new <tt>CreateCallback</tt> support function which allows you to perform direct callbacks from functions in external DLLs (like Windows API functions) to functions in your script. See the help file and the <i>CodeDll.iss</i> example script for an example.</li>
     <li>[Setup] section directives <tt>ChangesAssociations</tt> and <tt>ChangesEnvironment</tt> may now be set to a boolean expression, which may contain calls to check functions.</li>
     <li>[Setup] section directives <tt>ChangesAssociations</tt> and <tt>ChangesEnvironment</tt> may now be set to a boolean expression, which may contain calls to check functions.</li>
     <li>Added new special-purpose <i>HelpTextNote</i> message that can be used to specify one or more lines of text that are added to the list of parameters in the summary shown when passing /HELP on the command line. This message defaults to an empty string so make sure to provide a non-empty default for all languages from your main script if you want to use it.</li>
     <li>Added new special-purpose <i>HelpTextNote</i> message that can be used to specify one or more lines of text that are added to the list of parameters in the summary shown when passing /HELP on the command line. This message defaults to an empty string so make sure to provide a non-empty default for all languages from your main script if you want to use it.</li>
     <li>Added new <tt>SameStr</tt> and <tt>SameText</tt> support functions.</li>
     <li>Added new <tt>SameStr</tt> and <tt>SameText</tt> support functions.</li>
@@ -118,7 +119,7 @@ For conditions of distribution and use, see <a href="http://www.jrsoftware.org/f
   <li>Minor tweaks.</li>
   <li>Minor tweaks.</li>
 </ul>
 </ul>
 
 
-<p>Contributions via <a href="https://github.com/jrsoftware/issrc" target="_blank">GitHub</a>: Thanks to jogo-, Martin Prikryl, dscharrer, Kleuter, Gavin Lambert, Stef&aacute;n &Ouml;rvar Sigmundsson, DRON, and Kevin Puetz for their contributions.</p>
+<p>Contributions via <a href="https://github.com/jrsoftware/issrc" target="_blank">GitHub</a>: Thanks to jogo-, Martin Prikryl, dscharrer, Kleuter, Gavin Lambert, Stef&aacute;n &Ouml;rvar Sigmundsson, DRON, Kevin Puetz, and Sherlock Software for their contributions.</p>
 
 
 <p>Some messages have been added in this version:<!-- (<a href="https://github.com/jrsoftware/issrc/commit/b0cd1a0177b818e36734026c67dc24f01ad6a0d0">View differences in Default.isl</a>).--></p>
 <p>Some messages have been added in this version:<!-- (<a href="https://github.com/jrsoftware/issrc/commit/b0cd1a0177b818e36734026c67dc24f01ad6a0d0">View differences in Default.isl</a>).--></p>
 <ul>
 <ul>