CodeDll.iss 3.9 KB

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