michael@0: { michael@0: NSIS ExDLL example michael@0: (C) 2001 - Peter Windridge michael@0: michael@0: Fixed and formatted by Brett Dever michael@0: http://editor.nfscheats.com/ michael@0: michael@0: Tested in Delphi 7.0 michael@0: } michael@0: michael@0: library exdll; michael@0: michael@0: uses Windows; michael@0: michael@0: type michael@0: VarConstants = ( michael@0: INST_0, michael@0: INST_1, // $1 michael@0: INST_2, // $2 michael@0: INST_3, // $3 michael@0: INST_4, // $4 michael@0: INST_5, // $5 michael@0: INST_6, // $6 michael@0: INST_7, // $7 michael@0: INST_8, // $8 michael@0: INST_9, // $9 michael@0: INST_R0, // $R0 michael@0: INST_R1, // $R1 michael@0: INST_R2, // $R2 michael@0: INST_R3, // $R3 michael@0: INST_R4, // $R4 michael@0: INST_R5, // $R5 michael@0: INST_R6, // $R6 michael@0: INST_R7, // $R7 michael@0: INST_R8, // $R8 michael@0: INST_R9, // $R9 michael@0: INST_CMDLINE, // $CMDLINE michael@0: INST_INSTDIR, // $INSTDIR michael@0: INST_OUTDIR, // $OUTDIR michael@0: INST_EXEDIR, // $EXEDIR michael@0: INST_LANG, // $LANGUAGE michael@0: __INST_LAST michael@0: ); michael@0: TVariableList = INST_0..__INST_LAST; michael@0: pstack_t = ^stack_t; michael@0: stack_t = record michael@0: next: pstack_t; michael@0: text: PChar; michael@0: end; michael@0: michael@0: var michael@0: g_stringsize: integer; michael@0: g_stacktop: ^pstack_t; michael@0: g_variables: PChar; michael@0: g_hwndParent: HWND; michael@0: michael@0: function PopString(): string; michael@0: var michael@0: th: pstack_t; michael@0: begin michael@0: if integer(g_stacktop^) <> 0 then begin michael@0: th := g_stacktop^; michael@0: Result := PChar(@th.text); michael@0: g_stacktop^ := th.next; michael@0: GlobalFree(HGLOBAL(th)); michael@0: end; michael@0: end; michael@0: michael@0: procedure PushString(const str: string=''); michael@0: var michael@0: th: pstack_t; michael@0: begin michael@0: if integer(g_stacktop) <> 0 then begin michael@0: th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize)); michael@0: lstrcpyn(@th.text, PChar(str), g_stringsize); michael@0: th.next := g_stacktop^; michael@0: g_stacktop^ := th; michael@0: end; michael@0: end; michael@0: michael@0: function GetUserVariable(const varnum: TVariableList): string; michael@0: begin michael@0: if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then michael@0: Result := g_variables + integer(varnum) * g_stringsize michael@0: else michael@0: Result := ''; michael@0: end; michael@0: michael@0: procedure SetUserVariable(const varnum: TVariableList; const value: string); michael@0: begin michael@0: if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then michael@0: lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value)) michael@0: end; michael@0: michael@0: procedure NSISDialog(const text, caption: string; const buttons: integer); michael@0: begin michael@0: MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons); michael@0: end; michael@0: michael@0: procedure ex_dll(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer); cdecl; michael@0: begin michael@0: // setup global variables michael@0: g_stringsize := string_size; michael@0: g_hwndParent := hwndParent; michael@0: g_stacktop := stacktop; michael@0: g_variables := variables; michael@0: // end global variable setup michael@0: michael@0: NSISDialog(GetUserVariable(INST_0), 'The value of $0', MB_OK); michael@0: NSISDialog(PopString, 'pop', MB_OK); michael@0: PushString('Hello, this is a push'); michael@0: SetUserVariable(INST_0, 'This is user var $0'); michael@0: end; michael@0: michael@0: exports ex_dll; michael@0: michael@0: begin michael@0: end.