Cazax
2009-01-30 08:01:17
First of all, you need delphi 7(If you don't have it look at EvilChicken's sig) and basic delphi knowledge.
Open Delphi.
Now we start creating the plugin:

Select Dll Wizard:

You will see this:

In uses, add:
Now, add your functions.
Function example:
procedure example:
If you need to call functions from SCAR(like Writeln), declare a variable:
and how to fill in Writeln:
So, if you need color finding related functions, you will have to use the handle of the client and search each pixel. Example:
Using types from the plugin:
Now, that you have your functions, we have to export them.
First function:
Second function:
third function:
fourth function:
sType = type's name
sTypeDef = what does the type have (example : record ExampleName : string; ExampleID : Integer; End;).
These are all the functions. How would your plugin will look like?:
Finally, compiling it to a .Dll:
Save the project in plugins folder.
Press run.
You will get this:

But look at the plugins folder, there it is!:
Open Delphi.
Now we start creating the plugin:

Select Dll Wizard:

You will see this:

In uses, add:
FastShareMem,
SysUtils,
Classes,
Windows,
Graphics;Now, add your functions.
Function example:
Function MiddleBox(X1, Y1, X2, Y2 : Integer): TPoint; stdcall;
Begin
Result.X := (X1 + X2) Shr 1;
Result.Y := (Y1 + Y2) Shr 1;
End;procedure example:
Procedure MiddleBox(X1, Y1, X2, Y2 : Integer; var TP : TPoint) stdcall;
Begin
TP.X := (X1 + X2) Shr 1;
TP.Y := (Y1 + Y2) Shr 1;
End;If you need to call functions from SCAR(like Writeln), declare a variable:
Type
TSCARPlugFunc = record
Name: string;
Ptr: Pointer;
end;
TWriteln = procedure(s : string);
var
Writeln : TWriteln; and how to fill in Writeln:
procedure SetFunctions(Funcs: array of TSCARPlugFunc); stdcall;
var
i: Integer;
begin
for i := 0 to Length(Funcs) - 1 do
if Funcs[i].Name = 'Writeln' then
Writeln := Funcs[i].Ptr;
end;Then in your functions you can call Writeln. Remember there are only few function you can call from SCAR. You can check them at Plugins/Accessable SCAR Functions.So, if you need color finding related functions, you will have to use the handle of the client and search each pixel. Example:
Function BlackPixelsInMS(DC : Cardinal): Integer; Stdcall;
Var
Canvas : TCanvas;
I, J : Integer;
Begin
Result := 0;
Canvas := TCanvas.Create;
Canvas.Handle := DC;
For I := 4 to 516 Do
For J := 4 to 338 Do
If Canvas.Pixels[I, J] = ClBlack Then
Inc(Result);
Canvas.Free;
End;Using types from the plugin:
Type
TExample = Record
ExampleName : String;
ExampleID : Integer;
End;
Function GetExample: TExample; Stdcall;
Begin
Result.ExampleName := 'Tutorial';
Result.ExampleID := 1;
End;Now, that you have your functions, we have to export them.
First function:
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 2;
end;Change this to the number of functions you are exporting. In this case, 2;(Function MiddleBox and blackPixelsInMS).Second function:
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall;
begin
case x of
0:
begin
ProcAddr := @MiddleBox;
StrPCopy(ProcDef, 'function MiddleBox(X1, Y1, X2, Y2 : Integer): TPoint;');
end;
1:
begin
ProcAddr := @blackPixelsInMS;
StrPCopy(ProcDef, 'function blackPixelsInMS(DC : Cardinal): Integer;');
end;
else
x := -1;
end;
Result := x;
end;x cases are the number of functions you are exporting starting from 0. ProcAddr is your function. Change the string in StrPCopy to your function's name (example function blackPixelsInMS(DC : Cardinal): Integer;).third function:
function GetTypeCount(): Integer; stdcall; export;
begin
Result := 1;
end;Change this to number of types you are exporting. In this case 1(TExample).fourth function:
function GetTypeInfo(x: Integer; var sType, sTypeDef: string): Integer; stdcall;
begin
case x of
0:
begin
sType := 'TExample';
sTypeDef := 'record ExampleName : string; ExampleID : Integer; End;';
end;
else
x := -1;
end;
Result := x;
end;
x cases = number of typessType = type's name
sTypeDef = what does the type have (example : record ExampleName : string; ExampleID : Integer; End;).
These are all the functions. How would your plugin will look like?:
library CazaxPlugin;
uses
FastShareMem,
SysUtils,
Classes,
Windows,
Graphics;
{$R *.res}
Function MiddleBox(X1, Y1, X2, Y2 : Integer): TPoint; stdcall;
Begin
Result.X := (X1 + X2) Shr 1;
Result.Y := (Y1 + Y2) Shr 1;
End;
Function BlackPixelsInMS(DC : Cardinal): Integer; Stdcall;
Var
Canvas : TCanvas;
I, J : Integer;
Begin
Result := 0;
Canvas := TCanvas.Create;
Canvas.Handle := DC;
For I := 4 to 516 Do
For J := 4 to 338 Do
If Canvas.Pixels[I, J] = ClBlack Then
Inc(Result);
Canvas.Free;
End;
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 2;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall;
begin
case x of
0:
begin
ProcAddr := @MiddleBox;
StrPCopy(ProcDef, 'function MiddleBox(X1, Y1, X2, Y2 : Integer): TPoint;');
end;
1:
begin
ProcAddr := @blackPixelsInMS;
StrPCopy(ProcDef, 'function blackPixelsInMS(DC : Cardinal): Integer;');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount;
exports GetFunctionInfo;
end.
Finally, compiling it to a .Dll:
Save the project in plugins folder.
Press run.
You will get this:

But look at the plugins folder, there it is!: