other-licenses/nsis/Contrib/ExDLL/exdll.dpr

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/nsis/Contrib/ExDLL/exdll.dpr	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +{
     1.5 +  NSIS ExDLL example
     1.6 +  (C) 2001 - Peter Windridge
     1.7 +
     1.8 +  Fixed and formatted by Brett Dever
     1.9 +  http://editor.nfscheats.com/
    1.10 +
    1.11 +  Tested in Delphi 7.0
    1.12 +}
    1.13 +
    1.14 +library exdll;
    1.15 +
    1.16 +uses Windows;
    1.17 +
    1.18 +type
    1.19 +  VarConstants = (
    1.20 +    INST_0,
    1.21 +    INST_1,       // $1
    1.22 +    INST_2,       // $2
    1.23 +    INST_3,       // $3
    1.24 +    INST_4,       // $4
    1.25 +    INST_5,       // $5
    1.26 +    INST_6,       // $6
    1.27 +    INST_7,       // $7
    1.28 +    INST_8,       // $8
    1.29 +    INST_9,       // $9
    1.30 +    INST_R0,      // $R0
    1.31 +    INST_R1,      // $R1
    1.32 +    INST_R2,      // $R2
    1.33 +    INST_R3,      // $R3
    1.34 +    INST_R4,      // $R4
    1.35 +    INST_R5,      // $R5
    1.36 +    INST_R6,      // $R6
    1.37 +    INST_R7,      // $R7
    1.38 +    INST_R8,      // $R8
    1.39 +    INST_R9,      // $R9
    1.40 +    INST_CMDLINE, // $CMDLINE
    1.41 +    INST_INSTDIR, // $INSTDIR
    1.42 +    INST_OUTDIR,  // $OUTDIR
    1.43 +    INST_EXEDIR,  // $EXEDIR
    1.44 +    INST_LANG,    // $LANGUAGE
    1.45 +    __INST_LAST
    1.46 +    );
    1.47 +  TVariableList = INST_0..__INST_LAST;
    1.48 +  pstack_t = ^stack_t;
    1.49 +  stack_t = record
    1.50 +    next: pstack_t;
    1.51 +    text: PChar;
    1.52 +  end;
    1.53 +
    1.54 +var
    1.55 +  g_stringsize: integer;
    1.56 +  g_stacktop: ^pstack_t;
    1.57 +  g_variables: PChar;
    1.58 +  g_hwndParent: HWND;
    1.59 +
    1.60 +function PopString(): string;
    1.61 +var
    1.62 +  th: pstack_t;
    1.63 +begin
    1.64 +  if integer(g_stacktop^) <> 0 then begin
    1.65 +    th := g_stacktop^;
    1.66 +    Result := PChar(@th.text);
    1.67 +    g_stacktop^ := th.next;
    1.68 +    GlobalFree(HGLOBAL(th));
    1.69 +  end;
    1.70 +end;
    1.71 +
    1.72 +procedure PushString(const str: string='');
    1.73 +var
    1.74 +  th: pstack_t;
    1.75 +begin
    1.76 +  if integer(g_stacktop) <> 0 then begin
    1.77 +    th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize));
    1.78 +    lstrcpyn(@th.text, PChar(str), g_stringsize);
    1.79 +    th.next := g_stacktop^;
    1.80 +    g_stacktop^ := th;
    1.81 +  end;
    1.82 +end;
    1.83 +
    1.84 +function GetUserVariable(const varnum: TVariableList): string;
    1.85 +begin
    1.86 +  if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
    1.87 +    Result := g_variables + integer(varnum) * g_stringsize
    1.88 +  else
    1.89 +    Result := '';
    1.90 +end;
    1.91 +
    1.92 +procedure SetUserVariable(const varnum: TVariableList; const value: string);
    1.93 +begin
    1.94 +  if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
    1.95 +    lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value))
    1.96 +end;
    1.97 +
    1.98 +procedure NSISDialog(const text, caption: string; const buttons: integer);
    1.99 +begin
   1.100 +  MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons);
   1.101 +end;
   1.102 +
   1.103 +procedure ex_dll(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer); cdecl;
   1.104 +begin
   1.105 +  // setup global variables
   1.106 +  g_stringsize := string_size;
   1.107 +  g_hwndParent := hwndParent;
   1.108 +  g_stacktop := stacktop;
   1.109 +  g_variables := variables;
   1.110 +  // end global variable setup
   1.111 +
   1.112 +  NSISDialog(GetUserVariable(INST_0), 'The value of $0', MB_OK);
   1.113 +  NSISDialog(PopString, 'pop', MB_OK);
   1.114 +  PushString('Hello, this is a push');
   1.115 +  SetUserVariable(INST_0, 'This is user var $0');
   1.116 +end;
   1.117 +
   1.118 +exports ex_dll;
   1.119 +
   1.120 +begin
   1.121 +end.

mercurial