unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
PPluginInfo = ^TPluginInfo;
TPluginInfo =
record
CommandWord:
String
[
10
];
Index:
Integer
;
Handle: THandle;
end
;
type
TForm1 =
class
(TForm)
TestLog: TMemo;
SendTest: TMemo;
procedure
SendTestKeyPress(Sender: TObject;
var
Key:
Char
);
procedure
komands(UIN, Msg:
String
; nomer:
integer
);
procedure
LoadPlug(fileName:
string
);
procedure
FormCreate(Sender: TObject);
procedure
FormClose(Sender: TObject;
var
Action: TCloseAction);
private
public
end
;
var
Form1: TForm1;
listKomand: TList;
listPlug: TStringList;
implementation
{$R *.dfm}
procedure
TForm1
.
SendTestKeyPress(Sender: TObject;
var
Key:
Char
);
begin
if
Key = #
13
then
begin
key:=
Char
(
0
);
komands(
'4815162342'
,SendTest
.
Text,
666
);
SendTest
.
Clear;
end
;
end
;
procedure
TForm1
.
FormCreate(Sender: TObject);
var
SearchRec : TSearchRec;
begin
listPlug:=TStringList
.
Create;
listkomand:=TList
.
Create;
if
FindFirst(
'*.lol'
,faAnyFile, SearchRec) =
0
then
begin
LoadPlug(SearchRec
.
name);
while
FindNext(SearchRec) =
0
do
LoadPlug(SearchRec
.
name);
FindClose(SearchRec);
end
;
end
;
procedure
TForm1
.
LoadPlug(fileName:
string
);
var
PlugName :
function
:
PChar
;
PlugKomand :
function
:
PChar
;
handle : THandle;
k,i:
integer
;
p: PPluginInfo;
komand:
string
;
LoadMain:
procedure
;
begin
handle := LoadLibrary(
Pchar
(FileName));
if
handle <>
0
then
begin
@PlugName := GetProcAddress(handle,
'PluginName'
);
if
@PlugName <>
nil
then
begin
@PlugKomand:=GetProcAddress(handle,
'Pluginkomand'
);
@LoadMain := GetProcAddress(handle,
'LoadMain'
);
LoadMain;
listPlug
.
Add(IntToStr(handle));
i:=
0
;
komand:=PlugKomand;
for
k:=
1
to
Length(komand)
do
if
(komand[k] =
';'
)
then
inc(i);
if
i>
0
then
for
k:=
1
to
i
do
begin
New(p);
p
.
CommandWord :=copy(komand,
1
,pos(
';'
,komand)-
1
);
p
.
Index := k-
1
;
p
.
Handle :=handle;
listKomand
.
Add(p);
komand:=copy(komand,pos(
';'
,komand)+
1
,length(komand));
end
;
New(p);
p
.
CommandWord :=komand;
p
.
Index := k-
1
;
p
.
Handle :=handle;
listKomand
.
Add(p);
end
else
ShowMessage(
'.lol not identifi '
);
end
;
end
;
procedure
TForm1
.
komands(UIN, Msg:
String
; nomer:
integer
);
var
n1,n2:
integer
;
PlugExec :
function
(Uin,Msg:
String
; index:
integer
):
PChar
;
komand:
string
;
Result:
string
;
begin
msg:=trim(msg);
n2:=pos(
' '
,Msg);
if
n2>
0
then
komand:=copy(Msg,
1
,n2-
1
)
else
komand:=Msg;
for
n1:=
0
to
listKomand
.
Count-
1
do
if
komand = PPluginInfo(listKomand
.
Items[n1])^.CommandWord
then
begin
@plugExec := GetProcAddress(PPluginInfo(listKomand
.
Items[n1])^.handle,
'PluginExec'
);
Result:=PlugExec(UIN, Msg,PPluginInfo(listKomand
.
Items[n1])^.Index);
TestLog
.
Lines
.
Add(Result);
TestLog
.
Lines
.
Add(
'############################'
);
end
;
end
;
procedure
TForm1
.
FormClose(Sender: TObject;
var
Action: TCloseAction);
var
k:
integer
;
handle: Thandle;
UnLoadMain:
procedure
;
begin
for
k:=
0
To
listPlug
.
Count-
1
do
begin
handle:=StrToInt(listPlug
.
Strings[k]);
@UnLoadMain := GetProcAddress(handle,
'UnLoadMain'
);
UnLoadMain;
FreeLibrary(handle)
end
;
end
;
end
.