CodeDll.iss 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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
  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. Source: "MyProg.exe"; DestDir: "{app}"
  17. Source: "MyProg.chm"; DestDir: "{app}"
  18. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  19. ; Install our DLL to {app} so we can access it at uninstall time.
  20. ; Use "Flags: dontcopy" if you don't need uninstall time access.
  21. Source: "MyDll.dll"; DestDir: "{app}"
  22. [Code]
  23. const
  24. MB_ICONINFORMATION = $40;
  25. // Importing a Unicode Windows API function.
  26. function MessageBox(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
  27. external 'MessageBoxW@user32.dll stdcall';
  28. // Importing an ANSI custom DLL function, first for Setup, then for uninstall.
  29. procedure MyDllFuncSetup(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  30. external 'MyDllFunc@files:MyDll.dll stdcall setuponly';
  31. procedure MyDllFuncUninstall(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  32. external 'MyDllFunc@{app}\MyDll.dll stdcall uninstallonly';
  33. // Importing an ANSI function for a DLL which might not exist at runtime.
  34. procedure DelayLoadedFunc(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  35. external 'DllFunc@DllWhichMightNotExist.dll stdcall delayload';
  36. function NextButtonClick(CurPage: Integer): Boolean;
  37. var
  38. hWnd: Integer;
  39. begin
  40. if CurPage = wpWelcome then begin
  41. hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
  42. MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
  43. MyDllFuncSetup(hWnd, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  44. try
  45. // If this DLL does not exist (it shouldn't), an exception will be raised. Press F9 to continue.
  46. DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
  47. except
  48. // <Handle missing dll here>
  49. end;
  50. end;
  51. Result := True;
  52. end;
  53. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  54. begin
  55. // Call our function just before the actual uninstall process begins.
  56. if CurUninstallStep = usUninstall then begin
  57. MyDllFuncUninstall(0, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  58. // Now that we're finished with it, unload MyDll.dll from memory.
  59. // We have to do this so that the uninstaller will be able to remove the DLL and the {app} directory.
  60. UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
  61. end;
  62. end;
  63. // The following shows how to use callbacks.
  64. function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: Longword): Longword;
  65. external 'SetTimer@user32.dll stdcall';
  66. var
  67. TimerCount: Integer;
  68. procedure MyTimerProc(Arg1, Arg2, Arg3, Arg4: Longword);
  69. begin
  70. Inc(TimerCount);
  71. WizardForm.BeveledLabel.Caption := ' Timer! ' + IntToStr(TimerCount) + ' ';
  72. WizardForm.BeveledLabel.Visible := True;
  73. end;
  74. procedure InitializeWizard;
  75. begin
  76. SetTimer(0, 0, 1000, CreateCallback(@MyTimerProc));
  77. end;