exdll_with_unit.dpr 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. {
  2. NSIS ExDLL2 example
  3. Original is ExDLL
  4. (C) 2001 - Peter Windridge
  5. Changed with delphi unit nsis.pas
  6. by bernhard mayer
  7. Tested in Delphi 7.0
  8. }
  9. // Example NSIS code
  10. {
  11. Section
  12. exdll_with_unit::registerplugincallback
  13. StrCpy $3 "Hello"
  14. Push "World"
  15. exdll_with_unit::pop_dlg_push
  16. Pop $1
  17. DetailPrint $$1=$1
  18. DetailPrint $$3=$3
  19. GetFunctionAddress $0 nsistest
  20. Push $0
  21. exdll_with_unit::callnsisfunc
  22. SectionEnd
  23. Function nsistest
  24. DetailPrint "Hello from NSIS function"
  25. FunctionEnd
  26. }
  27. library exdll;
  28. uses
  29. nsis, windows;
  30. {$IFDEF UNICODE}
  31. type TString = System.WideString; // UnicodeString?
  32. type PTChar = PWideChar;
  33. {$ELSE}
  34. type TString = AnsiString;
  35. type PTChar = PAnsiChar;
  36. {$ENDIF}
  37. procedure pop_dlg_push(const hwndParent: HWND; const string_size: integer; const variables: PTChar; const stacktop: pointer); cdecl;
  38. begin
  39. // set up global variables
  40. Init(hwndParent, string_size, variables, stacktop);
  41. NSISDialog(GetUserVariable(INST_3), 'The value of $3', MB_OK);
  42. NSISDialog(PopString, 'pop', MB_OK);
  43. PushString('Hello, this is a push');
  44. SetUserVariable(INST_3, 'This is user var $3');
  45. end;
  46. procedure callnsisfunc(const hwndParent: HWND; const string_size: integer; const variables: PTChar; const stacktop: pointer; const extraparameters: pointer); cdecl;
  47. var
  48. FuncAddr : TString;
  49. begin
  50. Init(hwndParent, string_size, variables, stacktop, extraparameters);
  51. FuncAddr := PopString();
  52. Call(FuncAddr);
  53. end;
  54. function mynsiscallback(const NSPIM: TNSPIM): Pointer; cdecl;
  55. begin
  56. Result := nil;
  57. if NSPIM = NSPIM_UNLOAD then
  58. begin
  59. NSISDialog(PTChar('NSPIM_UNLOAD is the final callback, goodbye...'), PTChar('mynsiscallback'), MB_OK);
  60. end;
  61. end;
  62. procedure registerplugincallback(const hwndParent: HWND; const string_size: integer; const variables: PTChar; const stacktop: pointer; const extraparameters: pointer); cdecl;
  63. var
  64. ThisDllInstance : HMODULE;
  65. begin
  66. Init(hwndParent, string_size, variables, stacktop, extraparameters);
  67. if g_extraparameters <> nil then
  68. begin
  69. ThisDllInstance := hInstance;
  70. TRegisterPluginCallback(g_extraparameters.RegisterPluginCallback)(ThisDllInstance, @mynsiscallback);
  71. end;
  72. end;
  73. exports pop_dlg_push;
  74. exports callnsisfunc;
  75. exports registerplugincallback;
  76. begin
  77. end.