|
|
Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. | First lets start a new delphi project. For the purpose of this exercise,
we will select the DLL Wizard.
2. Save the project as whatever you want, but remember the name as you
will need this for later use when you $define the library for conditional compilation.
3. add a unit to the DLL project, this is your DLL interface unit, name it something like myDLLInt.pas
4. No you are ready to code your DLL and interface.
Let start with 2 simple add/subtract functions that can be called from the DLL via the interface.
Here is the source to the actual DLL that we will use:
library adder;
uses
SysUtils,Classes,adderInt;
{$R *.res}
function addNumbers(num1:integer;num2:integer):integer;stdcall;
begin
Result := num1+num2;
end;
function subNumbers(num1:integer;num2:integer):integer;stdcall;
begin
Result:=num1-num2;
end;
exports
addNumbers,subNumbers;
end.
Notice that my units uses has the adderInt specified as I named my interface unit adderInt.pas.
These are the actual functions that will be called.
NEXT:
We must write an interface that will allow the calling of our DLL
functions form other applications namely C/C++ apps and of course Delphi apps.
The source code for your interface will look like this:
unit adderInt;
interface
{$IFNDEF ADDER}
function addNumbers(num1:integer;num2:integer):integer;stdcall;
function subNumbers(num1:integer;num2:integer):integer;stdcall;
{$ENDIF}
implementation
{$IFNDEF ADDER}
function addNumbers; external 'ADDER.DLL' name 'addNumbers';
function subNumbers; external 'ADDER.DLL' name 'subNumbers';
{$ENDIF}
end.
Thats it! Compile the project and now you should have a DLL called yourname.dll
To use this DLL you must do 3 things:
1. Place the yourfile.dll into the same directory as your EXE or Project you are writing.
2. Add the interface unit to your current project. eg mylibInt.pas
3. Add the interface to your uses in your project. eg. uses
sysutils,mydllint
there ya go, you just coded a DLL
Email me at support@cttech.net with any questions.
| |
Other 6 submission(s) by this author
|
|
|
Report Bad Submission |
|
|
Your Vote! |
See Voting Log |
|
Other User Comments |
1/15/2003 8:05:50 AM: Please, give me a little concept about
client/server and more database
|
5/2/2003 9:01:51 AM: I have created the DLL. Howw do you
call it from other projects?
|
|
Add Your Feedback! |
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. |
|