From aec369dfbc423575b715a785121dc9e514c05e87 Mon Sep 17 00:00:00 2001 From: kichik Date: Wed, 6 Aug 2003 16:53:52 +0000 Subject: [PATCH] New Delphi unit for NSIS plug-ins by Bernhard Mayer git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2791 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/ExDLL/exdll_with_unit.dpr | 37 +++++++++ Contrib/ExDLL/nsis.pas | 120 ++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 Contrib/ExDLL/exdll_with_unit.dpr create mode 100644 Contrib/ExDLL/nsis.pas diff --git a/Contrib/ExDLL/exdll_with_unit.dpr b/Contrib/ExDLL/exdll_with_unit.dpr new file mode 100644 index 00000000..f21a336b --- /dev/null +++ b/Contrib/ExDLL/exdll_with_unit.dpr @@ -0,0 +1,37 @@ +{ + NSIS ExDLL2 example + Original is ExDLL + (C) 2001 - Peter Windridge + + Changed with delphi unit nsis.pas + by bernhard mayer + + Tested in Delphi 7.0 +} + +library exdll; + +uses + nsis, windows; + +function ex_dll(hwndParent: HWND; string_size: integer; variables: PChar; stacktop: pointer):integer; cdecl; +var + c: PChar; + buf: array[0..1024] of char; +begin + // set up global variables + Init(hwndParent,string_size,variables,stacktop); + + c:=GetUserVariable(INST_0); + MessageBox(g_hwndParent,c,'The value of $0',MB_OK); + PopString(@buf); + MessageBox(g_hwndParent,@buf,'pop',MB_OK); + PushString(PChar('Hello, this is a push')); + + Result:=1; +end; + +exports ex_dll; + +begin +end. diff --git a/Contrib/ExDLL/nsis.pas b/Contrib/ExDLL/nsis.pas new file mode 100644 index 00000000..0a36baeb --- /dev/null +++ b/Contrib/ExDLL/nsis.pas @@ -0,0 +1,120 @@ +{ + Original Code from + (C) 2001 - Peter Windridge + + Code in seperate unit and some changes + 2003 by Bernhard Mayer + + simple include this unit in your plugin project and export + functions as needed +} + + +unit nsis; + +interface + +uses + windows; + +type + VarConstants = ( + INST_0, + INST_1, // $1 + INST_2, // $2 + INST_3, // $3 + INST_4, // $4 + INST_5, // $5 + INST_6, // $6 + INST_7, // $7 + INST_8, // $8 + INST_9, // $9 + INST_R0, // $R0 + INST_R1, // $R1 + INST_R2, // $R2 + INST_R3, // $R3 + INST_R4, // $R4 + INST_R5, // $R5 + INST_R6, // $R6 + INST_R7, // $R7 + INST_R8, // $R8 + INST_R9, // $R9 + INST_CMDLINE, // $CMDLINE + INST_INSTDIR, // $INSTDIR + INST_OUTDIR, // $OUTDIR + INST_EXEDIR, // $EXEDIR + INST_LANG, // $LANGUAGE + __INST_LAST + ); + TVariableList = INST_0..__INST_LAST; + pstack_t = ^stack_t; + stack_t = record + next: pstack_t; + text: PChar; + end; + +var + g_stringsize: integer; + g_stacktop: ^pstack_t; + g_variables: PChar; + g_hwndParent: HWND; + +procedure Init(hwndParent: HWND; string_size: integer; variables: PChar; stacktop: pointer); +function PopString(str: PChar):integer; +function PushString(str: PChar):integer; +function GetUserVariable(varnum: TVariableList):PChar; + +implementation + +procedure Init(hwndParent: HWND; string_size: integer; variables: PChar; stacktop: pointer); +begin + g_stringsize:=string_size; + g_hwndParent:=hwndParent; + g_stacktop:=stacktop; + g_variables:=variables; +end; + +function PopString(str: PChar):integer; +var + th: pstack_t; +begin + if integer(g_stacktop^) = 0 then + begin + Result:=1; + Exit; + end; + th:=g_stacktop^; + lstrcpy(str,@th.text); + g_stacktop^ := th.next; + GlobalFree(HGLOBAL(th)); + Result:=0; +end; + +function PushString(str: PChar):integer; +var + th: pstack_t; +begin + if integer(g_stacktop) = 0 then + begin + Result:=1; + Exit; + end; + th:=pstack_t(GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize)); + lstrcpyn(@th.text,str,g_stringsize); + th.next:=g_stacktop^; + g_stacktop^:=th; + Result:=0; +end; + +function GetUserVariable(varnum: TVariableList):PChar; +begin + if (integer(varnum) < 0) or (integer(varnum) >= integer(__INST_LAST)) then + begin + Result:=''; + Exit; + end; + Result:=g_variables+integer(varnum)*g_stringsize; +end; + +begin +end.