Applied patch #838864 - String-friendly Delphi ExDLL

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3136 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2003-11-13 13:04:54 +00:00
parent d27d6dfb57
commit c775c5a3e8
3 changed files with 82 additions and 104 deletions

View file

@ -2,10 +2,10 @@
NSIS ExDLL example
(C) 2001 - Peter Windridge
Fixed and formatted by Alexander Tereschenko
http://futuris.plastiqueweb.com/
Fixed and formatted by Brett Dever
http://editor.nfscheats.com/
Tested in Delphi 6.01
Tested in Delphi 7.0
}
library exdll;
@ -54,75 +54,62 @@ var
g_variables: PChar;
g_hwndParent: HWND;
function PopString(str: PChar):integer;
function PopString(): string;
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;
if integer(g_stacktop^) <> 0 then begin
th := g_stacktop^;
Result := PChar(@th.text);
g_stacktop^ := th.next;
GlobalFree(HGLOBAL(th));
end;
end;
function PushString(str: PChar):integer;
procedure PushString(const str: string='');
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;
if integer(g_stacktop) <> 0 then begin
th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize));
lstrcpyn(@th.text, PChar(str), g_stringsize);
th.next := g_stacktop^;
g_stacktop^ := th;
end;
end;
function GetUserVariable(varnum: TVariableList):PChar;
function GetUserVariable(varnum: TVariableList): string;
begin
if (integer(varnum) < 0) or (integer(varnum) >= integer(__INST_LAST)) then
begin
Result:='';
Exit;
end;
Result:=g_variables+integer(varnum)*g_stringsize;
if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
Result := g_variables + integer(varnum) * g_stringsize
else
Result := '';
end;
procedure SetUserVariable(varnum: TVariableList; value: PChar);
procedure SetUserVariable(varnum: TVariableList; value: string);
begin
if (value <> nil) and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
begin
lstrcpy(g_variables+integer(varnum)*g_stringsize,value);
end;
if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value))
end;
function ex_dll(hwndParent: HWND; string_size: integer; variables: PChar; stacktop: pointer):integer; cdecl;
var
c: PChar;
buf: array[0..1024] of char;
procedure NSISDialog(text, caption: string; buttons: integer);
begin
MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons);
end;
procedure ex_dll(hwndParent: HWND; string_size: integer; variables: PChar; stacktop: pointer); cdecl;
begin
// set up global variables
g_stringsize:=string_size;
g_hwndParent:=hwndParent;
g_stringsize:=string_size;
g_stacktop:=stacktop;
g_variables:=variables;
g_stringsize := string_size;
g_hwndParent := hwndParent;
g_stringsize := string_size;
g_stacktop := stacktop;
g_variables := variables;
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;
NSISDialog(GetUserVariable(INST_0), 'The value of $0', MB_OK);
NSISDialog(PopString, 'pop', MB_OK);
PushString('Hello, this is a push');
SetUserVariable(INST_0, 'This is 0');
end;
exports ex_dll;

View file

@ -14,21 +14,15 @@ 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;
procedure ex_dll(hwndParent: HWND; string_size: integer; variables: PChar; stacktop: pointer); cdecl;
begin
// set up global variables
Init(hwndParent,string_size,variables,stacktop);
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;
NSISDialog(GetUserVariable(INST_0), 'The value of $0', MB_OK);
NSISDialog(PopString, 'pop', MB_OK);
PushString('Hello, this is a push');
SetUserVariable(INST_0, 'This is 0');
end;
exports ex_dll;

View file

@ -5,7 +5,10 @@
Code in seperate unit and some changes
2003 by Bernhard Mayer
simple include this unit in your plugin project and export
Fixed and formatted by Brett Dever
http://editor.nfscheats.com/
simply include this unit in your plugin project and export
functions as needed
}
@ -60,10 +63,11 @@ var
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;
function SetUserVariable(varnum: TVariableList; value: PChar):integer;
function PopString(): string;
procedure PushString(const str: string='');
function GetUserVariable(varnum: TVariableList): string;
procedure SetUserVariable(varnum: TVariableList; value: string);
procedure NSISDialog(text, caption: string; buttons: integer);
implementation
@ -75,54 +79,47 @@ begin
g_variables:=variables;
end;
function PopString(str: PChar):integer;
function PopString(): string;
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;
if integer(g_stacktop^) <> 0 then begin
th := g_stacktop^;
Result := PChar(@th.text);
g_stacktop^ := th.next;
GlobalFree(HGLOBAL(th));
end;
end;
function PushString(str: PChar):integer;
procedure PushString(const str: string='');
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;
if integer(g_stacktop) <> 0 then begin
th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize));
lstrcpyn(@th.text, PChar(str), g_stringsize);
th.next := g_stacktop^;
g_stacktop^ := th;
end;
end;
function GetUserVariable(varnum: TVariableList):PChar;
function GetUserVariable(varnum: TVariableList): string;
begin
if (integer(varnum) < 0) or (integer(varnum) >= integer(__INST_LAST)) then
begin
Result:='';
Exit;
end;
Result:=g_variables+integer(varnum)*g_stringsize;
if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
Result := g_variables + integer(varnum) * g_stringsize
else
Result := '';
end;
procedure SetUserVariable(varnum: TVariableList; value: PChar);
procedure SetUserVariable(varnum: TVariableList; value: string);
begin
if (value <> nil) and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
begin
lstrcpy(g_variables+integer(varnum)*g_stringsize,value);
end;
if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value))
end;
procedure NSISDialog(text, caption: string; buttons: integer);
begin
MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons);
end;
begin