home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Contrib / ExDLL / exdll.dpr < prev    next >
Text File  |  2003-11-16  |  3KB  |  119 lines

  1. {
  2.   NSIS ExDLL example
  3.   (C) 2001 - Peter Windridge
  4.  
  5.   Fixed and formatted by Brett Dever
  6.   http://editor.nfscheats.com/
  7.  
  8.   Tested in Delphi 7.0
  9. }
  10.  
  11. library exdll;
  12.  
  13. uses Windows;
  14.  
  15. type
  16.   VarConstants = (
  17.     INST_0,
  18.     INST_1,       // $1
  19.     INST_2,       // $2
  20.     INST_3,       // $3
  21.     INST_4,       // $4
  22.     INST_5,       // $5
  23.     INST_6,       // $6
  24.     INST_7,       // $7
  25.     INST_8,       // $8
  26.     INST_9,       // $9
  27.     INST_R0,      // $R0
  28.     INST_R1,      // $R1
  29.     INST_R2,      // $R2
  30.     INST_R3,      // $R3
  31.     INST_R4,      // $R4
  32.     INST_R5,      // $R5
  33.     INST_R6,      // $R6
  34.     INST_R7,      // $R7
  35.     INST_R8,      // $R8
  36.     INST_R9,      // $R9
  37.     INST_CMDLINE, // $CMDLINE
  38.     INST_INSTDIR, // $INSTDIR
  39.     INST_OUTDIR,  // $OUTDIR
  40.     INST_EXEDIR,  // $EXEDIR
  41.     INST_LANG,    // $LANGUAGE
  42.     __INST_LAST
  43.     );
  44.   TVariableList = INST_0..__INST_LAST;
  45.   pstack_t = ^stack_t;
  46.   stack_t = record
  47.     next: pstack_t;
  48.     text: PChar;
  49.   end;
  50.  
  51. var
  52.   g_stringsize: integer;
  53.   g_stacktop: ^pstack_t;
  54.   g_variables: PChar;
  55.   g_hwndParent: HWND;
  56.  
  57. function PopString(): string;
  58. var
  59.   th: pstack_t;
  60. begin
  61.   if integer(g_stacktop^) <> 0 then begin
  62.     th := g_stacktop^;
  63.     Result := PChar(@th.text);
  64.     g_stacktop^ := th.next;
  65.     GlobalFree(HGLOBAL(th));
  66.   end;
  67. end;
  68.  
  69. procedure PushString(const str: string='');
  70. var
  71.   th: pstack_t;
  72. begin
  73.   if integer(g_stacktop) <> 0 then begin
  74.     th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize));
  75.     lstrcpyn(@th.text, PChar(str), g_stringsize);
  76.     th.next := g_stacktop^;
  77.     g_stacktop^ := th;
  78.   end;
  79. end;
  80.  
  81. function GetUserVariable(const varnum: TVariableList): string;
  82. begin
  83.   if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
  84.     Result := g_variables + integer(varnum) * g_stringsize
  85.   else
  86.     Result := '';
  87. end;
  88.  
  89. procedure SetUserVariable(const varnum: TVariableList; const value: string);
  90. begin
  91.   if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
  92.     lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value))
  93. end;
  94.  
  95. procedure NSISDialog(const text, caption: string; const buttons: integer);
  96. begin
  97.   MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons);
  98. end;
  99.  
  100. procedure ex_dll(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer); cdecl;
  101. begin
  102.   // setup global variables
  103.   g_stringsize := string_size;
  104.   g_hwndParent := hwndParent;
  105.   g_stacktop := stacktop;
  106.   g_variables := variables;
  107.   // end global variable setup
  108.  
  109.   NSISDialog(GetUserVariable(INST_0), 'The value of $0', MB_OK);
  110.   NSISDialog(PopString, 'pop', MB_OK);
  111.   PushString('Hello, this is a push');
  112.   SetUserVariable(INST_0, 'This is user var $0');
  113. end;
  114.  
  115. exports ex_dll;
  116.  
  117. begin
  118. end.
  119.