forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeDll.iss
80 lines (66 loc) · 2.93 KB
/
CodeDll.iss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
; -- CodeDll.iss --
;
; This script shows how to call DLL functions at runtime from a [Code] section.
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DisableProgramGroupPage=yes
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
; Install our DLL to {app} so we can access it at uninstall time
; Use "Flags: dontcopy" if you don't need uninstall time access
Source: "MyDll.dll"; DestDir: "{app}"
[Code]
const
MB_ICONINFORMATION = $40;
//importing an ANSI Windows API function
function MessageBox(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal): Integer;
external '[email protected] 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
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
procedure DelayLoadedFunc(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
external '[email protected] stdcall delayload';
function NextButtonClick(CurPage: Integer): Boolean;
var
hWnd: Integer;
begin
if CurPage = wpWelcome then begin
hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
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
DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
except
//handle missing dll here
end;
end;
Result := True;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
// Call our function just before the actual uninstall process begins
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.
// We have to do this so that the uninstaller will be able to remove the DLL and the {app} directory.
UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
end;
end;