A very basic example: Create a DLL with a SumInteger function, that simply adds two integer values:
1) Go to File->New->Other
2) In the "New Items" dialog select "DLL Wizard" and click OK
3) The generated code looks like this:
library Project1;
uses
SysUtils,
Classes;
{$R *.res}
begin
end.
4) Remove SysUtils and Classes from the uses clause and add Windows instead. Save the project.
5) Now we write the function. We also want to "export" this function, that means other programs (in this case DBP) can access this function. So the source will now look like this
library Project1;
uses
Windows;
{$R *.res}
function SumInteger(Value1, Value2: LongInt): LongInt; cdecl;
begin
result := Value1 + Value2;
end;
exports
SumInteger;
begin
end.
6) Now create a simple text file and call it "cmdtable.rc". Save it in the directory of this Delphi project. The file should contain:
STRINGTABLE
Begin
1, "SUM INTEGER[%LLL%SumInteger%Value1, Value2"
End
7) Now open a console (cmd.exe) and switch to the project directory and call Borland's resource compiler:
This will create a file called cmdtable.RES. We need to bind that to our Project. So the complete source code looks like this:
library Project1;
uses
Windows;
{$R *.res}
{$R cmdtable.res}
function SumInteger(Value1, Value2: LongInt): LongInt; cdecl;
begin
result := Value1 + Value2;
end;
exports
SumInteger;
begin
end.
8) Compile the project. Now you can copy the compile DLL in DBPro's user-plugins folder. To access the command type
life = Sum Integer(41+1)
print life
sync
wait key
Play Nice!
Play Basic!
Version 1.02 available now!