|
|
 |
Now we give you a simple plugin example in Delphi (testplugin.dpr):
testplugin.dpr
library TestPlugin;
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
Sharemem, SysUtils, Classes,
UnitMain in 'UnitMain.pas';
{$R *.res}
exports
GetPluginInfo,
GetReplyMessagePI;
begin
end. |
unitmain.pas
unit UnitMain;
interface
uses
SysUtils;
type
CharSet = Set of char;
function GetPluginInfo(var sPluginName, CurrentVer: PChar): Boolean; export; stdcall;
function GetReplyMessagePI(const sCommand, sMSNAccount: PChar;
var sReplyMessage,FN,EF,CO,CS: PChar; var sMessageType: Integer): Boolean; export; stdcall;
function WordAt(const Text : string; Position : Integer) : string;
function ExtractWord(N:Integer;S:String; WordDelims: CharSet): String;
implementation
function GetPluginInfo(var sPluginName, CurrentVer: PChar):Boolean;
begin
sPluginName := 'Test Plugin';
CurrentVer := '1.0';
Result := true;
end;
function GetReplyMessagePI(const sCommand, sMSNAccount: PChar;
var sReplyMessage,FN,EF,CO,CS: PChar; var sMessageType: Integer): Boolean;
var
para1,para2: String;
begin
FN := 'Arial';
CS := '1';
sMessageType := 0;
if Uppercase(WordAt(sCommand,1)) = 'THANKS' then
begin
sReplyMessage := PChar('Not at all');
EF := 'I';
CO := 'BB00CC';
end
else
begin
if Uppercase(WordAt(sCommand,1)) = 'HELLO' then
begin
sReplyMessage := PChar('Hello !');
EF := 'BI';
CO := 'EE00AA';
end
else
begin
if Uppercase(WordAt(sCommand,1) = 'PLUS' then
begin
para1 := WordAt(sCommand,2);
para2 := WordAt(sCommand,3);
if (para1 <> '') and (para2 <> '') then
begin
sReplyMessage := para1 + '+' + para2 + '=' + PChar(StrToInt(para1) + StrToInt(para2));
EF := 'B';
CO := '800000';
end
else
begin
sReplyMessage := 'Invalid parameters';
EF := 'B';
CO := '000080';
end;
end;
end;
end;
Result := true;
end;
function WordAt(const Text : string; Position : Integer) : string;
begin
Result := ExtractWord(Position, Text, [' ']);
end;
function ExtractWord(N: Integer; S: String; WordDelims: CharSet): String;
var
I,J:Word;
Count:Integer;
SLen:Integer;
begin
Count := 0;
I := 1;
Result := '';
SLen := Length(S);
while I <= SLen do
begin
while (I <= SLen) And (S[I] In WordDelims) do Inc(I);
if I <= SLen then Inc(Count);
J := I;
while (J <= SLen) And Not(S[J] In WordDelims) do
Inc(J);
if Count = N then
begin
Result := Copy(S,I,J-I);
Exit;
end;
I := J;
end; {while}
end;
end. |
|