|
@@ -1,11 +1,12 @@
|
|
|
; -- 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]
|
|
|
AppName=My Program
|
|
|
AppVersion=1.5
|
|
|
-DisableWelcomePage=no
|
|
|
DefaultDirName={autopf}\My Program
|
|
|
DisableProgramGroupPage=yes
|
|
|
UninstallDisplayIcon={app}\MyProg.exe
|
|
@@ -23,26 +24,18 @@ Source: "MyDll.dll"; DestDir: "{app}"
|
|
|
const
|
|
|
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);
|
|
|
external 'MyDllFunc@files:MyDll.dll stdcall setuponly';
|
|
|
|
|
|
procedure MyDllFuncUninstall(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
|
|
|
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);
|
|
|
external '[email protected] stdcall delayload';
|
|
|
|
|
@@ -50,7 +43,7 @@ function NextButtonClick(CurPage: Integer): Boolean;
|
|
|
var
|
|
|
hWnd: Integer;
|
|
|
begin
|
|
|
- if CurPage = wpWelcome then begin
|
|
|
+ if CurPage = wpSelectDir then begin
|
|
|
hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
|
|
|
|
|
|
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);
|
|
|
|
|
|
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);
|
|
|
except
|
|
|
- //handle missing dll here
|
|
|
+ // <Handle missing dll here>
|
|
|
end;
|
|
|
end;
|
|
|
Result := True;
|
|
@@ -70,8 +63,7 @@ end;
|
|
|
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
|
|
|
begin
|
|
|
// 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);
|
|
|
|
|
|
// Now that we're finished with it, unload MyDll.dll from memory.
|
|
@@ -79,3 +71,23 @@ begin
|
|
|
UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
|
|
|
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;
|