CodeDll.iss 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ; -- CodeDll.iss --
  2. ;
  3. ; This script shows how to call DLL functions at runtime from a [Code] section.
  4. [Setup]
  5. AppName=My Program
  6. AppVersion=1.5
  7. DefaultDirName={pf}\My Program
  8. DisableProgramGroupPage=yes
  9. UninstallDisplayIcon={app}\MyProg.exe
  10. OutputDir=userdocs:Inno Setup Examples Output
  11. [Files]
  12. Source: "MyProg.exe"; DestDir: "{app}"
  13. Source: "MyProg.chm"; DestDir: "{app}"
  14. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  15. ; Install our DLL to {app} so we can access it at uninstall time
  16. ; Use "Flags: dontcopy" if you don't need uninstall time access
  17. Source: "MyDll.dll"; DestDir: "{app}"
  18. [Code]
  19. const
  20. MB_ICONINFORMATION = $40;
  21. //importing an ANSI Windows API function
  22. function MessageBox(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal): Integer;
  23. external 'MessageBoxA@user32.dll stdcall';
  24. //importing a Windows API function, automatically choosing ANSI or Unicode (requires ISPP)
  25. //function MessageBox(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
  26. //#ifdef UNICODE
  27. //external 'MessageBoxW@user32.dll stdcall';
  28. //#else
  29. //external 'MessageBoxA@user32.dll stdcall';
  30. //#endif
  31. //importing an ANSI custom DLL function, first for Setup, then for uninstall
  32. procedure MyDllFuncSetup(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  33. external 'MyDllFunc@files:MyDll.dll stdcall setuponly';
  34. procedure MyDllFuncUninstall(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  35. external 'MyDllFunc@{app}\MyDll.dll stdcall uninstallonly';
  36. //importing an ANSI function for a DLL which might not exist at runtime
  37. procedure DelayLoadedFunc(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal);
  38. external 'DllFunc@DllWhichMightNotExist.dll stdcall delayload';
  39. function NextButtonClick(CurPage: Integer): Boolean;
  40. var
  41. hWnd: Integer;
  42. begin
  43. if CurPage = wpWelcome then begin
  44. hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
  45. MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
  46. MyDllFuncSetup(hWnd, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  47. try
  48. //if this DLL does not exist (it shouldn't), an exception will be raised
  49. DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
  50. except
  51. //handle missing dll here
  52. end;
  53. end;
  54. Result := True;
  55. end;
  56. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  57. begin
  58. // Call our function just before the actual uninstall process begins
  59. if CurUninstallStep = usUninstall then
  60. begin
  61. MyDllFuncUninstall(0, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  62. // Now that we're finished with it, unload MyDll.dll from memory.
  63. // We have to do this so that the uninstaller will be able to remove the DLL and the {app} directory.
  64. UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
  65. end;
  66. end;