2
0

CodeDll.iss 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ; -- CodeDll.iss --
  2. ;
  3. ; This script shows how to call functions in external DLLs (like Windows API functions)
  4. ; at runtime and how to perform direct callbacks from these functions to functions
  5. ; in the script.
  6. [Setup]
  7. AppName=My Program
  8. AppVersion=1.5
  9. WizardStyle=modern dynamic
  10. DefaultDirName={autopf}\My Program
  11. DisableProgramGroupPage=yes
  12. DisableWelcomePage=no
  13. UninstallDisplayIcon={app}\MyProg.exe
  14. OutputDir=userdocs:Inno Setup Examples Output
  15. [Files]
  16. ; Install our DLL to {app} so we can access it at uninstall time.
  17. ; Use "Flags: dontcopy noencryption" if you don't need uninstall time access.
  18. Source: "MyDll.dll"; DestDir: "{app}"
  19. ; Place any regular files here, so *after* all your dontcopy DLL files.
  20. Source: "MyProg.exe"; DestDir: "{app}"
  21. Source: "MyProg.chm"; DestDir: "{app}"
  22. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  23. [Code]
  24. const
  25. MB_ICONINFORMATION = $40;
  26. // Importing a Unicode Windows API function.
  27. function MessageBox(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
  28. external '[email protected] stdcall';
  29. // Importing an ANSI custom DLL function, first for Setup, then for uninstall.
  30. procedure MyDllFuncSetup(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  31. external 'MyDllFunc@files:MyDll.dll stdcall setuponly';
  32. procedure MyDllFuncUninstall(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  33. external 'MyDllFunc@{app}\MyDll.dll stdcall uninstallonly';
  34. // Importing an ANSI function for a DLL which might not exist at runtime.
  35. procedure DelayLoadedFunc(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  36. external '[email protected] stdcall delayload';
  37. function NextButtonClick(CurPage: Integer): Boolean;
  38. var
  39. hWnd: Integer;
  40. begin
  41. if CurPage = wpWelcome then begin
  42. hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
  43. MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
  44. MyDllFuncSetup(hWnd, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  45. try
  46. // If this DLL does not exist (it shouldn't), an exception will be raised. Press F9 to continue.
  47. DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
  48. except
  49. // <Handle missing dll here>
  50. end;
  51. end;
  52. Result := True;
  53. end;
  54. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  55. begin
  56. // Call our function just before the actual uninstall process begins.
  57. if CurUninstallStep = usUninstall then begin
  58. MyDllFuncUninstall(0, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  59. // Now that we're finished with it, unload MyDll.dll from memory.
  60. // We have to do this so that the uninstaller will be able to remove the DLL and the {app} directory.
  61. UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
  62. end;
  63. end;
  64. // The following shows how to use callbacks.
  65. function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: Longword): Longword;
  66. external '[email protected] stdcall';
  67. function KillTimer(hWnd, nIDEvent: Longword): Bool;
  68. external '[email protected] stdcall';
  69. var
  70. TimerID, TimerCount: Integer;
  71. procedure MyTimerProc(Arg1, Arg2, Arg3, Arg4: Longword);
  72. begin
  73. if WizardForm <> nil then begin
  74. Inc(TimerCount);
  75. WizardForm.BeveledLabel.Caption := ' Timer! ' + IntToStr(TimerCount) + ' ';
  76. WizardForm.BeveledLabel.Visible := True;
  77. end;
  78. end;
  79. procedure InitializeWizard;
  80. begin
  81. TimerID := SetTimer(0, 0, 1000, CreateCallback(@MyTimerProc));
  82. end;
  83. procedure DeinitializeSetup;
  84. begin
  85. if TimerID <> 0 then
  86. KillTimer(0, TimerID);
  87. end;